idlFormatDatetime(datetime: string, timezone: string): string { return this.momentizeDateTimeString(datetime, timezone).toISOString(); }
/**
+ * Create a Moment from an ISO string
+ */
+ momentizeIsoString(isoString: string, timezone: string): Moment {
+ return (isoString.length) ? Moment(isoString, timezone) : Moment();
+ }
+
+ /**
* Turn a date string into a Moment using the date format org setting.
*/
- momentizeDateString(date: string, timezone: string, strict = false): Moment {
- return this.momentize(date, this.makeFormatParseable(this.dateFormat), timezone, strict);
+ momentizeDateString(date: string, timezone: string, strict?, locale?): Moment {
+ return this.momentize(date, this.makeFormatParseable(this.dateFormat, locale), timezone, strict);
}
/**
* Turn a datetime string into a Moment using the datetime format org setting.
*/
- momentizeDateTimeString(date: string, timezone: string, strict = false): Moment {
- return this.momentize(date, this.makeFormatParseable(this.dateTimeFormat), timezone, strict);
+ momentizeDateTimeString(date: string, timezone: string, strict?, locale?): Moment {
+ return this.momentize(date, this.makeFormatParseable(this.dateTimeFormat, locale), timezone, strict);
}
/**
}
return Moment.tz(date, format, false, timezone);
}
- // TODO: The following fallback returns the date at midnight UTC,
- // rather than midnight in the local TZ
- return Moment.tz(date, timezone);
+ return Moment(new Date(date), timezone);
}
}
*/
private makeFormatParseable(original: string, locale?: string): string {
if (!original) { return ''; }
- if (!locale) { locale = locale; }
+ if (!locale) { locale = this.locale.currentLocaleCode(); }
switch (original) {
case 'short': {
const template = getLocaleDateTimeFormat(locale, FormatWidth.Short);
return this.formatter.transform({value: value, datatype: datatype});
}
}
+
});
it('should transform M/d/yy, h:mm a Angular format string to a valid MomentJS one', () => {
- const momentVersion = service['makeFormatParseable']('M/d/yy, h:mm a');
+ const momentVersion = service['makeFormatParseable']('M/d/yy, h:mm a', 'en-US');
expect(momentVersion).toBe('M/D/YY, h:mm a');
});
it('should transform MMM d, y, h:mm:ss a Angular format string to a valid MomentJS one', () => {
- const momentVersion = service['makeFormatParseable']('MMM d, y, h:mm:ss a');
+ const momentVersion = service['makeFormatParseable']('MMM d, y, h:mm:ss a', 'ar-JO');
expect(momentVersion).toBe('MMM D, Y, h:mm:ss a');
});
it('should transform MMMM d, y, h:mm:ss a z Angular format strings to a valid MomentJS one', () => {
- const momentVersion = service['makeFormatParseable']('MMMM d, y, h:mm:ss a z');
+ const momentVersion = service['makeFormatParseable']('MMMM d, y, h:mm:ss a z', 'fr-CA');
expect(momentVersion).toBe('MMMM D, Y, h:mm:ss a [GMT]Z');
});
it('should transform full Angular format strings to a valid MomentJS one using Angular locale en-US', () => {
});
it('can create a valid Momentjs object given a valid datetime string and a dateTimeFormat from org settings', () => {
service['dateTimeFormat'] = 'M/D/YY, h:mm a';
- const moment = service.momentizeDateTimeString('7/3/12, 6:06 PM', 'Africa/Addis_Ababa', false);
+ const moment = service.momentizeDateTimeString('7/3/12, 6:06 PM', 'Africa/Addis_Ababa', false, 'fr-CA');
expect(moment.isValid()).toBe(true);
});