All files / src/fieldcontrols DateTime.ts

81.25% Statements 13/16
100% Branches 0/0
50% Functions 2/4
78.57% Lines 11/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51            1x 1x   1x 1x 1x 1x                         1x   3x 3x               1x             3x              
/**
 * @module FieldControls
 * 
 */ /** */
 
 
import { bindable, autoinject } from 'aurelia-framework'
import { FieldBaseControl } from './FieldBaseControl';
import { FieldSettings } from 'sn-client-js';
import { LocaleService } from '../services';
import 'moment';
import * as moment from 'moment-timezone';
import { MDCTextField } from '@material/textfield/dist/mdc.textfield';
 
 
 
/**
 * Field control that represents a Date and Time Picker. Formatting will be done based on the LocaleService. Local time will be displayed, but UTC will be bound to the field's Value
 * Usage:
 * 
 * ``` html
 * <date-time content.bind="content" settings.bind="myDateTimeFieldSettings"></date-time>
 * ```
 */
@autoinject
export class DateTime extends FieldBaseControl<string, FieldSettings.DateTimeFieldSetting> {
 
    constructor(public localeService: LocaleService) {
        super();
    }
 
    datefield: HTMLElement;
    mdcDateField: MDCTextField;
 
 
    @bindable
    parsedValue: string;
 
    parsedValueChanged(){
        this.value = moment.tz(this.parsedValue, this.localeService.Timezone).toISOString();
    }
 
    attached() {
        this.mdcDateField = new MDCTextField(this.datefield);
    }
 
    activate(model){
        super.activate(model);
        this.parsedValue = moment.utc(this.value).tz(this.localeService.Timezone).format(this.localeService.DateTimeFormat);
    }
}