Question

I am looking for the best way to handle Dates & Times on my SpineJS models. I am working on creating an event calendar of sorts. The first hurdle being to display a nice 6 week calendar. It must start on the last Sunday of the previous month, ending on the first Saturday of the next month.

I was using DateJs (http://www.datejs.com/) and handling some date things in the View template but wanted to move some of this to a model to cleanup said view.

The function I am working on is called 'firstDay'. This will find the date where we start our calendar (the last Sunday of the previous month)

  firstDay: () ->
    Date.today().set({month: @month}).moveToFirstDayOfMonth().moveToDayOfWeek(0, -1)

My attempted usage:

<% day = cal.firstDay %>

  // initialize the table header, etc

  <tbody>
    <% while !day.equals(cal.lastDay): %>
    // render each calendar tile/square

And here is the error:

Uncaught TypeError: Object function () {
      return Date.today().set({
        month: this.month
      }).moveToFirstDayOfMonth().moveToDayOfWeek(0, -1);
    } has no method 'equals'

So my Spine model appears to be unaware of DateJS... I guess that makes sense. It looks like the function itself is being returned, not the evaluation of the function... if that makes sense.

Any guidance here would be appreciated on the best way to incorporate dates and times into my models.

thanks

Était-ce utile?

La solution

So my problem was quite simple... syntax. Being very new to coffescript and spinejs I guess I was looking at too many things at once and missed the obvious.

The proper way to call this function from a coffeescript/eco template is:

<% day = cal.firstDay() %>

I was missing the parenthesis on the function call. This mistake should be easy to recognize if I run across the error again in the future. In fact it should have been obvious in the first place... again, too many new things.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top