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

Weekday is 2 today - Monday #46

Closed
pieman64 opened this issue Aug 8, 2016 · 5 comments
Closed

Weekday is 2 today - Monday #46

pieman64 opened this issue Aug 8, 2016 · 5 comments

Comments

@pieman64
Copy link

pieman64 commented Aug 8, 2016

Weekday() is showing as 2 today but your notes indicate Sunday is 0 so surely Monday should be 1.

Please advise.

I am guessing you mean Sunday is zero index, but physically day 1.

@ljruiten
Copy link

I have had a quick look through the source code and at the weekday function there is a little comment that says: // sunday is day 1, so the documentation is wrong. Sunday comes first in the index, but it is indexed at 1 and not at 0.

Today is Friday and that returns 6. I then tried weekday(now() + 86400); (the amount of seconds in a day) and it started returning 7. And weekday(now() + 172800); returns 1. So sunday = 1 and saturday = 7.

So to summarize if you want to have it 0 indexed (like I did) just subtract 1. This should either be updated in the documentation or fixed in the source code though, because in any case one of them is wrong... I believe this is a bug in the source, because it usually is the convention to return 0 for a sunday.

@smz
Copy link

smz commented Mar 10, 2017

I'm an "intruder" here as I'm not currently using this library, but I think 0 = Sunday based weekdays (as used in the standard C time library) makes sense as you can perform "modulo 7" modular arithmetic on "number of days"

P.S.: ... and same goes for months: 0 = January ...

@PaulStoffregen
Copy link
Owner

PaulStoffregen commented Mar 10, 2017

The readme says "day of the week (1-7), Sunday is day 1". The Arduino Playground documentation says "Day of the week, Sunday is day 1".

I've edited the playground page to now say "Day of the week (1-7), Sunday is day 1".

Sorry, this library is not going to make an incompatible change to 0-6 that will break so many existing programs. It's just not going to happen. Please stop asking. I do not care that the C library functions use a different convention. This library uses 1-7 and that range is well documented. If you want 0-6, you can subtract 1. Deal with it!

If there is any incorrect documentation, please tell me specifically where you see it? @pieman64 you wrote "but your notes indicate Sunday is 0". Where do you see this info?

@PaulStoffregen
Copy link
Owner

PaulStoffregen commented Mar 10, 2017

Likewise, month() is not changing to zero based. @michaelmargolis (the original author of this library) and I talked about the API in person. This is a very well established library, since the very early days of Arduino, now used by many thousands of programs.

We are not going to make incompatible API changes. It does not matter if the standard C library follows a different convention. For incompatible API changes, the final definitive answer is no.

@smz
Copy link

smz commented Mar 11, 2017

Thanks, I perfectly understand the rationale behind your choices (and agree, although this surely is not much important!)

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

No branches or pull requests

4 participants