/**
* Create an IDL-friendly display version of a human-readable date
*/
- idlFormatDate(date: string): string { return this.momentizeDateString(date).format('YYYY-MM-DD'); }
+ idlFormatDate(date: string, timezone: string): string { return this.momentizeDateString(date, timezone).format('YYYY-MM-DD'); }
/**
* Create an IDL-friendly display version of a human-readable datetime
*/
- idlFormatDatetime(datetime: string): string { return this.momentizeDateTimeString(datetime).toISOString(); }
+ idlFormatDatetime(datetime: string, timezone: string): string { return this.momentizeDateTimeString(datetime, timezone).toISOString(); }
- momentizeDateString(date: string): Moment {
+ momentizeDateString(date: string, timezone: string): Moment {
const parseableFormat = this.makeFormatParseable(this.dateFormat);
- if (parseableFormat.length) {return Moment(date, parseableFormat, 'Asia/Tokyo')};
- return Moment(date, 'Asia/Tokyo');
+ if (parseableFormat.length) {return Moment(date, parseableFormat, timezone)};
+ return Moment(date, timezone);
}
- momentizeDateTimeString(datetime: string): Moment {
+ momentizeDateTimeString(datetime: string, timezone: string): Moment {
const parseableFormat = this.makeFormatParseable(this.dateTimeFormat);
- if (parseableFormat.length) {return Moment(datetime, parseableFormat, 'Asia/Tokyo')};
- return Moment(datetime, 'Asia/Tokyo');
+ if (parseableFormat.length) {return Moment(datetime, parseableFormat, timezone)};
+ return Moment(datetime, timezone);
}
/**
@Input() domId = '';
@Input() fieldName: string;
@Input() required: boolean;
- @Input() minuteStep: number;
+ @Input() minuteStep: number = 15;
@Input() showTZ = true;
- @Input() timezone: string;
+ @Input() timezone: string = this.format.wsOrgTimezone;
@Input() readOnly = false;
@Input() initialIso: string;
}
ngOnInit() {
- const start = this.initialIso ? Moment(this.initialIso) : Moment();
+ const start = this.initialIso ? Moment(this.initialIso, this.timezone) : Moment(new Date(), this.timezone);
this.setDefaultDate(start);
this.setDefaultTime(start);
}
setDefaultTime(start: any) {
- const remainder = 5 - start.minute() % 5,
- final = Moment(start).add(remainder, 'minutes');
+ const remainder = this.minuteStep - start.minute() % this.minuteStep,
+ final = Moment(start, this.timezone).add(remainder, 'minutes');
- // Seed time model with current, rounding up to nearest 5 minutes (does roll hour over if needed)
+ // Seed time model with current, rounding up to nearest granularity minutes (does roll hour over if needed)
this.timeModel = { hour: final.hour(), minute: final.minute(), second: 0 };
}
let newDate: Moment;
if (event) { // if the change came from the input field
- newDate = this.format.momentizeDateTimeString(this.stringVersion);
+ newDate = this.format.momentizeDateTimeString(this.stringVersion, this.timezone);
} else {
newDate = Moment(new Date(this.dateModel.year, (this.dateModel.month - 1), this.dateModel.day,
- this.timeModel.hour, this.timeModel.minute, this.timeModel.second));
+ this.timeModel.hour, this.timeModel.minute, this.timeModel.second), this.timezone);
}
if (newDate && !isNaN(newDate)) {
recId: any;
// Show datetime fields in this particular timezone
- timezone: string;
+ timezone: string = this.format.wsOrgTimezone;
// IDL record we are editing
// TODO: allow this to be update in real time by the caller?
rec[field.name]('f');
}
} else if ( field.datatype === 'timestamp' && field.datetime && rec[field.name]() ) {
- rec[field.name] = this.format.idlFormatDatetime(rec[field.name]())
+ rec[field.name] = this.format.idlFormatDatetime(rec[field.name](), this.timezone);
} else if (field.datatype === 'org_unit') {
const org = rec[field.name]();
if (org && typeof org === 'object') {