Skip to content

Instantly share code, notes, and snippets.

@TomKearney
Created December 19, 2018 22:59
Show Gist options
  • Select an option

  • Save TomKearney/4b41fc6828de200e5e68c8416a9c88f8 to your computer and use it in GitHub Desktop.

Select an option

Save TomKearney/4b41fc6828de200e5e68c8416a9c88f8 to your computer and use it in GitHub Desktop.
Angular override to attempt to workaround shortfalls of PrimeNg Calendar control
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