Created
December 19, 2018 22:59
-
-
Save TomKearney/4b41fc6828de200e5e68c8416a9c88f8 to your computer and use it in GitHub Desktop.
Angular override to attempt to workaround shortfalls of PrimeNg Calendar control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Directive, Host, Self, HostListener } from '@angular/core'; | |
| import { Calendar } from 'primeng/primeng'; | |
| import { getMomentDate } from '../datetime/date-time.utils'; | |
| @Directive({ selector: '[appUtcOverride]' }) | |
| export class PrimeNgCalendarUtcDirective { | |
| constructor(@Host() @Self() private calendar: Calendar) { | |
| } | |
| @HostListener('onSelect', ['$event']) onSelect() { | |
| this.toUtc(); | |
| } | |
| @HostListener('onInput', ['$event']) onInput() { | |
| this.toUtc(); | |
| } | |
| private toUtc() { | |
| const date = new Date(this.calendar.value.getFullYear() | |
| , this.calendar.value.getMonth() | |
| , this.calendar.value.getDate() | |
| , this.calendar.currentHour, this.calendar.currentMinute, 0); | |
| this.calendar.value = getMomentDate(date); | |
| this.calendar.updateModel(this.calendar.value); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment