spacetime icon indicating copy to clipboard operation
spacetime copied to clipboard

unixFmt('ww') wrong / Calender Week of Year

Open nmaas87 opened this issue 4 years ago • 4 comments

Dear all,

var s = spacetime.now();
s = s.goto('UTC');
console.log(s.unixFmt('ww'));

is giving me 33, while it is Calender Week 32... Any ideas?

nmaas87 avatar Aug 13 '21 07:08 nmaas87

hey thanks Nico, apologies for the delay.

if you run this in the cli: date +"So this is week: %U" it appears our results are in-line with the unix date command. That's what we should return, i think.

I think it's probably just a off-by-one confusion, can you confirm? thanks

spencermountain avatar Aug 22 '21 20:08 spencermountain

Hey there :) Sorry I cannot confirm:

https://man7.org/linux/man-pages/man1/date.1.html

%U     week number of year, with Sunday as first day of week
              (00..53)

trying this in WSL gives me: So this is week: 34 (I am on a Windows 10, German machine, but as date is configuring Sunday to be first day of the new week (in Germany we have monday as first day ;)) - this is correct)

Spacetime tells me on the same machine its week: 34, so far so good.

However, if I set the machines date to tomorrow (Monday), date tells me still week 34, but spacetime tells me its week 35, So it looks like Spacetime trys to match with the German timesystem (changing week count from sunday->monday but its off by one).

So I started adding a "Calendar Week: " + (s.unixFmt('ww')-1); which worked out and has been flawless for me.

I guess its an ugly error to search for, and I should not bandaid in that way, but I needed some solution fast :)

Cheers,

Nico

nmaas87 avatar Aug 22 '21 21:08 nmaas87

oh right - good observation. If I remember, we define weeks as starting on monday, and the first week is one with a thursday in it. I can look into how the unix command defines it, and write some documentation. cheers

spencermountain avatar Aug 23 '21 13:08 spencermountain

Yeah, but it seems to be still one week ahead of the real one and I have to decrement 1 as written above. Maybe you could check if its something you could observe as well :)

nmaas87 avatar Aug 23 '21 13:08 nmaas87