Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nmaas87 opened this issue Aug 13, 2021 · 4 comments
Open

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

nmaas87 opened this issue Aug 13, 2021 · 4 comments
Labels

Comments

@nmaas87
Copy link

nmaas87 commented Aug 13, 2021

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?

@spencermountain
Copy link
Owner

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

@nmaas87
Copy link
Author

nmaas87 commented Aug 22, 2021

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

@spencermountain
Copy link
Owner

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

@nmaas87
Copy link
Author

nmaas87 commented Aug 23, 2021

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants