Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

%j is not padded by zeros! #22

Closed
haisamido opened this Issue · 8 comments

2 participants

Haisam Ido Sami Samhuri
Haisam Ido

According to the 'Supported Specifiers' section:

j is the day of the year, padded to 3 digits (001-366)

while:

console.log(strftime('%Y-%jT%H:%M:%S', new Date('2013-04-09T15:16:00.000Z')));

returns without a padded zero:

2013-99T11:16:00

but should be:

2013-099T15:16:00

It also appears that the function doesn't preserve the timezone but converts it to the browsers timezone.

Haisam Ido

I believe if you replace lies 116, 117 and 118 in strftime.js:

      var y=new Date(d.getFullYear(), 0, 1);
      var day = Math.ceil((d.getTime() - y.getTime()) / (1000*60*60*24));
      return day;

with

     return pad( Math.floor((new Date(d) - new Date((new Date(d)).getFullYear(), 0, 0))/(1000 * 60 * 60 * 24)), 3);

should pad the day of year correctly. However, this doesn't take care of the timezone issue.

Sami Samhuri samsonjs closed this in 2e6443f
Sami Samhuri
Owner

Fixed, thanks for the report.

Sami Samhuri
Owner

Do you have an example I can test with for the timezone issue? It behaves correctly here (PST).

Haisam Ido

Try a date of this type: '2013-04-09T15:16:00.000Z' where Z is Zulu time, i.e. GMT, i.e. UTC. In EST it should be in 2013-04-09T10:16:00.000 (5 hours difference) but what should be returned is the date and time formated for the originally provided timezone and not changed to the local time zone.

Of course, I could be doing something wrong.

One would not see this problem if one's machine is set to UTC/GMT/Z because in that case local is the same as UTC.

Sami Samhuri
Owner
Haisam Ido

I see. Thanks for the feedback.

Sami Samhuri
Owner

No problem!

Haisam Ido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.