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

Default date value won't work when day of month < 10 #38

Closed
ChristianRomberg opened this issue Nov 30, 2017 · 1 comment
Closed

Default date value won't work when day of month < 10 #38

ChristianRomberg opened this issue Nov 30, 2017 · 1 comment

Comments

@ChristianRomberg
Copy link
Contributor

ChristianRomberg commented Nov 30, 2017

if (date instanceof Date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) month = "0" + month;
var day = date.getDate();
dateStr = year + "-" + month + "-" + day;

I think the issue is that when the day of month is less than 10, it is not formatted correctly. If I'm correct, the fix would be to just append a "0" to the day, just like it is done with the month.

Sorry, I only have a debugger screenshot with obfuscated source, but it should be pretty obvious whats going on here.

Screenshot

@ChristianRomberg
Copy link
Contributor Author

I just noticed you were using different code later down the line. One solution might be to consolidate the initial setting of the value and setValue into common code.

setValue: function (date) {
var dateStr;
if (date instanceof Date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
if (month < 10) month = "0" + month;
var day = date.getDate();
if (day < 10) day = "0" + day;
dateStr = year + "-" + month + "-" + day;
}

@bit101 bit101 closed this as completed in 04d2a54 Dec 18, 2017
bit101 added a commit that referenced this issue Dec 18, 2017
Consolidated the creation of date strings. Fixes #38
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

1 participant