samsonjs / strftime

strftime for JavaScript

Home Page:http://samhuri.net/projects/strftime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Account for DST offsets

Fauntleroy opened this issue · comments

I'm having trouble formatting a couple dates in November.

  • 2013-11-01 11:10PM
  • 2013-11-04 12:10PM

The first date renders properly, but the second date takes place after DST ends (November 2), so it's one hour off.

screen shot 2014-01-29 at 2 14 32 pm

Ideally, strftime would account for DST and take care of it behind the scenes.

Can you share the code you're using for this calculation? Keeping up to speed with DST every year is not something I care to take on, thus out of scope for the project.

There's got to be a way for this to be handled by the native Date's knowledge of DST.

I assume the problem is that November 1st inside DST, but right now we're not, so when we instantiate Date it uses the current DST status and doesn't keep track of it any further than that.

This is basically what I'm doing:

I have a Handlebars Helper:

var strftimeTZ = require('strftime').strftimeTZ;
var newDate = require('new-date');

module.exports = function( date_string, format, offset ){
    offset = ( typeof offset === 'number' ) ? offset : null;
    var date = newDate( date_string );
    return strftimeTZ( format, date, offset );
};

And I use the helper like so

{{formatDate publish_start "%b %-d, %Y @ %l:%M%p" timezone.offset}}

There's no way for strftime to know that the offset should be adjusted for DST. I suggest adjusting the offset before passing it in, if necessary. Closing this one.