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

Bug: Datetime picker defaults to 12 PM instead of 12 AM #3340

Open
shyamal890 opened this issue Aug 26, 2019 · 8 comments · May be fixed by #3378
Open

Bug: Datetime picker defaults to 12 PM instead of 12 AM #3340

shyamal890 opened this issue Aug 26, 2019 · 8 comments · May be fixed by #3378

Comments

@shyamal890
Copy link

shyamal890 commented Aug 26, 2019

Bug description:

When one selects a date through ngb-datepicker it automatically takes the time as 12PM when it should take 12 AM by default.

As seen in the demo below. Given I am in IST timezone (GMT+5:30) when I select say for example 15th Aug, 2019. I get the following output: 2019-08-15T06:30:00.000Z which is 15th Aug, 2019, 12 PM instead of expected 2019-08-14T18:30:00.000Z which is 15th Aug, 2019, 12 AM.

image

You can also check in Material it selects 12 AM: https://stackblitz.com/edit/material-datepicker-12am

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/ngb-datepicker-12pm-issue

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 82.3

ng-bootstrap: 5.0.0

Bootstrap: 4+

@shyamal890
Copy link
Author

@maxokorokov @pkozlowski-opensource Most of the UI tools out there have 12 AM as the default. Any idea on when the behavior would reverted back from 12 PM to 12 AM?

@shyamal890
Copy link
Author

Would appreciate a reply on this

@shyamal890
Copy link
Author

Kindly share an update on this bug.

@shyamal890
Copy link
Author

Dear team, would appreciate an update on this bug.

@gpolychronis
Copy link
Contributor

gpolychronis commented Mar 9, 2020

Hello @shyamal890 .
You can override the NgbDateNativeAdapter Injectable to provide your own implementation i.e:

`
@Injectable()
export class CustomAdapter extends NgbDateNativeAdapter {

protected _toNativeDate(date: NgbDateStruct): Date {
const jsDate = new Date(date.year, date.month - 1, date.day, 0);
// avoid 30 -> 1930 conversion
jsDate.setFullYear(date.year);
return jsDate;
}
}
`

Ensure to include it in your providers i.e:

providers: [ {provide: NgbDateAdapter, useClass: CustomAdapter} ]

See also example: https://ng-bootstrap.github.io/#/components/datepicker/examples#adapter

@shyamal890
Copy link
Author

@gpolychronis I will try this out and get back here.

@AGLearning
Copy link

When you use NgbDateNativeUTCAdapter instead of NgbDateNativeAdapter hour is correct (12AM UTC)

@linch90
Copy link

linch90 commented Nov 25, 2022

Dear ng-bootstrap team, provide a custom implementation for this adapter is a solution, but why not take 12AM as the default for the NgbDateNativeAdapter, while the NgbDateNativeUTCAdapter is 12AM default, what's the purpose for this 12PM implementation? It's really odd.

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

Successfully merging a pull request may close this issue.

5 participants