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

Allow UTC format in configuration #460

Closed
arthurRbr opened this issue Aug 28, 2018 · 6 comments
Closed

Allow UTC format in configuration #460

arthurRbr opened this issue Aug 28, 2018 · 6 comments
Labels

Comments

@arthurRbr
Copy link

arthurRbr commented Aug 28, 2018

Hello,

The moment adapter by @angular/material-moment-adapter offers a very convenient way of parsing all dates as UTC:

@NgModule({ imports: [MatDatepickerModule, MatMomentDateModule], providers: [ { provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } } ] })

See: https://github.com/angular/material2/blob/master/src/material-moment-adapter/adapter/moment-date-adapter.ts

Would you consider adding a similar option to this library? It would save me a lot of trouble ensuring consistency between locale and UTC dates.

Thanks a lot,

@DanielYKPan
Copy link
Owner

Update ng-pick-datetime and ng-pick-datetime-moment to latest versions.

Now you could

@NgModule({
  imports: [MatDatepickerModule, MatMomentDateModule], 
  providers: [ { provide: OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS, useValue: { useUtc: true } } ] 
})

@arthurRbr
Copy link
Author

Thanks a lot!

@PeterOeClausen
Copy link

PeterOeClausen commented Jun 7, 2019

Update ng-pick-datetime and ng-pick-datetime-moment to latest versions.

Now you could

@NgModule({
  imports: [MatDatepickerModule, MatMomentDateModule], 
  providers: [ { provide: OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS, useValue: { useUtc: true } } ] 
})

I want to display a UTC+0 date received from the server, however when I open the owlDateTimePicker it translates the date to my current timezone: UTC+2, and shows the day before!

I've added the provider you link to, and the owlDateTimePicker picks dates in UTC+0 correctly, however when reading UTC+0 dates it converts it to UTC+2.
How can I get rid of this error?

I've even tried setting:
{ provide: OWL_DATE_TIME_LOCALE, useValue: 'en-GB' }
{ provide: LOCALE_ID, useValue: 'en-GB' }
Without any changes...

Examples with screenshots are below

The date I receive (From Google console):
Console

The date shown in my UI:
UI

Opening the owlDateTimePicker:
owlDateTimePicker

@ehanken21
Copy link

@PeterOeClausen I'm having the same issue, only with UTC-7.

I have yet to fine a solution, hopefully @DanielYKPan can chime in on this.

A workaround that seems to fix it is just appending your local UTC offset to the date. In my case T07:00:00.000Z. So lets say I get the date 2019-06-10 from the server, I'm passing 2019-06-10T07:00:00.000Z to the picker. Then when I send the data back to the server, I only send the date component with date.toISOString().split('T')[0].

It's really hacky, but as of right now I don't see any other way.

@annmarie-switzer
Copy link

Update ng-pick-datetime and ng-pick-datetime-moment to latest versions.

Now you could

@NgModule({
  imports: [MatDatepickerModule, MatMomentDateModule], 
  providers: [ { provide: OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS, useValue: { useUtc: true } } ] 
})

Hey @DanielYKPan , How can I use this in conjunction with custom formats? I have tried this but it does not work:

providers: [
    { 
        provide: OWL_DATE_TIME_FORMATS, 
	useValue: [{ useUtc: true }, MY_MOMENT_FORMATS ]
    }
]

@paraneetharan
Copy link

@NgModule({
imports: [MatDatepickerModule, MatMomentDateModule],
providers: [ { provide: OWL_MOMENT_DATE_TIME_ADAPTER_OPTIONS, useValue: { useUtc: true } } ]
})
using this my IST time is showing as a UTC time in picker but after selecting time it is giving IST time

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

6 participants