-
Notifications
You must be signed in to change notification settings - Fork 119
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
format("z") should be 0-based #34
Comments
Hello, If you to be zero based you can use Math.floor instead of math.ceil and remove -1 :) var now = new Date(); I hope that will resolve your issue . Br, |
@elhidery unless I'm mistaken the question not about how to convert the function to be zero based (which is trivial indeed ;-). It is about (quoting the question): was there a motivation to not used zero-based numbering here? |
Hello again, I apologize for or misunderstanding. This.getFullYearr returns the current year which is "2018" the "0" refers to january because the months are zero based ,finally the day is stored as 1 because the domain in javascript is formatted from 1 to 31 ,if the day is written as "0" it will translate to the final day of the corresponding month. So the modulation to not use zero based numbering is to avoid conflicts with the javascript standards in which the value of "0" for the day corresponds to the maximum day value of the corresponding month. |
@elhidery unless I'm mistaken the question is not about the rationale for how zero is used in the Date function argument. It is about the range of values returned by the z function copy/pasted in the message. |
I ran a few test case scenarios and concluded that it is due to how JS subtracts. The test scenario that made this obvious was the following: The expected result should have been 335, yet the output was 366, which exceeds the range of the output and this occurs due to the way JS handles the subtraction. When the subtraction occurs JS deals with 0 and 1 as numbers. It does not reference the 0 to the max day value for the corresponding month as it should according to the dating standard. This results in an erroneous values if we made the date 0 based. |
The documentation in the README should probably be updated, then? It says "0-365" ;) |
PHP uses zero-based numbering for "z" in date formatting and returns values from 0 - 365. This library returns values from 1 - 366.
In my opinion, to fully mimic PHP, the function should end with a subtraction of 1:
(linebreaks added for readability)
Or was there a motivation to not used zero-based numbering here?
The text was updated successfully, but these errors were encountered: