From dfb53f86ec8e3a13c8b22770a3688550939bf5f6 Mon Sep 17 00:00:00 2001 From: Sean Hill Date: Fri, 15 Feb 2013 14:49:12 -0600 Subject: [PATCH 1/2] humanizeDuration is not in the definition file, so compilation fails. Removing these since humanizeDuration has been deprecated/removed. See https://github.com/timrwood/moment/pull/572 --- moment/moment-tests.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/moment/moment-tests.ts b/moment/moment-tests.ts index 1bb236ea3e..b158cfb475 100644 --- a/moment/moment-tests.ts +++ b/moment/moment-tests.ts @@ -126,13 +126,6 @@ moment([2007, 0, 29]).fromNow(); moment([2007, 0, 29]).fromNow(); moment([2007, 0, 29]).fromNow(true); -moment.humanizeDuration(1000 * 60); -moment.humanizeDuration(1, "seconds"); -moment.humanizeDuration(60000, true); -moment.humanizeDuration(1, "minutes", true); -moment.humanizeDuration(-60000, true); -moment.humanizeDuration(-1, "minutes", true); - var a8 = moment([2007, 0, 29]); var b8 = moment([2007, 0, 28]); a8.diff(b8) ; From 04517266de7fffd4469227819a887ebf13002341 Mon Sep 17 00:00:00 2001 From: Sean Hill Date: Fri, 15 Feb 2013 15:27:12 -0600 Subject: [PATCH 2/2] Add definitions for moment language customizations per issue #182. --- moment/moment-tests.ts | 152 ++++++++++++++++++++++++++++++++++++++++- moment/moment.d.ts | 65 ++++++++++++++++-- 2 files changed, 212 insertions(+), 5 deletions(-) diff --git a/moment/moment-tests.ts b/moment/moment-tests.ts index b158cfb475..5d77aa3d3a 100644 --- a/moment/moment-tests.ts +++ b/moment/moment-tests.ts @@ -228,4 +228,154 @@ moment.duration(500).asMilliseconds(); moment.duration(500).seconds(); moment.duration(500).asSeconds(); moment.duration().minutes(); -moment.duration().asMinutes(); \ No newline at end of file +moment.duration().asMinutes(); + +moment.lang('en', { + months : [ + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December" + ] +}); + +moment.lang('en', { + months : function (momentToFormat, format) { + // momentToFormat is the moment currently being formatted + // format is the formatting string + if (/^MMMM/.test(format)) { // if the format starts with 'MMMM' + return this.nominative[momentToFormat.month()]; + } else { + return this.subjective[momentToFormat.month()]; + } + } +}); + +moment.lang('en', { + monthsShort : [ + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + ] +}); + +moment.lang('en', { + monthsShort : function (momentToFormat, format) { + if (/^MMMM/.test(format)) { + return this.nominative[momentToFormat.month()]; + } else { + return this.subjective[momentToFormat.month()]; + } + } +}); + +moment.lang('en', { + weekdays : [ + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + ] +}); + +moment.lang('en', { + weekdays : function (momentToFormat, format) { + return this.weekdays[momentToFormat.day()]; + } +}); + +moment.lang('en', { + weekdaysShort : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] +}); + +moment.lang('en', { + weekdaysShort : function (momentToFormat, format) { + return this.weekdaysShort[momentToFormat.day()]; + } +}); + +moment.lang('en', { + weekdaysMin : ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] +}); + +moment.lang('en', { + weekdaysMin : function (momentToFormat, format) { + return this.weekdaysMin[momentToFormat.day()]; + } +}); + +moment.lang('en', { + longDateFormat : { + LT: "h:mm A", + L: "MM/DD/YYYY", + l: "M/D/YYYY", + LL: "MMMM Do YYYY", + ll: "MMM D YYYY", + LLL: "MMMM Do YYYY LT", + lll: "MMM D YYYY LT", + LLLL: "dddd, MMMM Do YYYY LT", + llll: "ddd, MMM D YYYY LT" + } +}); + +moment.lang('en', { + longDateFormat : { + LT: "h:mm A", + L: "MM/DD/YYYY", + LL: "MMMM Do YYYY", + LLL: "MMMM Do YYYY LT", + LLLL: "dddd, MMMM Do YYYY LT" + } +}); + +moment.lang('en', { + relativeTime : { + future: "in %s", + past: "%s ago", + s: "seconds", + m: "a minute", + mm: "%d minutes", + h: "an hour", + hh: "%d hours", + d: "a day", + dd: "%d days", + M: "a month", + MM: "%d months", + y: "a year", + yy: "%d years" + } +}); + +moment.lang('en', { + meridiem : function (hour, minute, isLowercase) { + if (hour < 9) { + return "早上"; + } else if (hour < 11 && minute < 30) { + return "上午"; + } else if (hour < 13 && minute < 30) { + return "中午"; + } else if (hour < 18) { + return "下午"; + } else { + return "晚上"; + } + } +}); + +moment.lang('en', { + calendar : { + lastDay : '[Yesterday at] LT', + sameDay : '[Today at] LT', + nextDay : function () { + return '[hoy a la' + ((this.hours() !== 1) ? 's' : '') + '] LT'; + }, + lastWeek : '[last] dddd [at] LT', + nextWeek : 'dddd [at] LT', + sameElse : 'L' + } +}); + +moment.lang('en', { + ordinal : function (number) { + var b = number % 10; + var output = (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + return number + output; + } +}); diff --git a/moment/moment.d.ts b/moment/moment.d.ts index 7a7b7d70cc..2ba80d175c 100644 --- a/moment/moment.d.ts +++ b/moment/moment.d.ts @@ -51,7 +51,6 @@ interface Duration { } - interface Moment { format(format: string): string; @@ -122,6 +121,64 @@ interface Moment { } +interface MomentCalendar { + + lastDay: any; + sameDay: any; + nextDay: any; + lastWeek: any; + nextWeek: any; + sameElse: any; + +} + +interface MomentLanguage { + + months?: any; + monthsShort?: any; + weekdays?: any; + weekdaysShort?: any; + weekdaysMin?: any; + longDateFormat?: MomentLongDateFormat; + relativeTime?: MomentRelativeTime; + meridiem?: (hour: number, minute: number, isLowercase: bool) => string; + calendar?: MomentCalendar; + ordinal?: (num: number) => string; + +} + +interface MomentLongDateFormat { + + L: string; + LL: string; + LLL: string; + LLLL: string; + LT: string; + l?: string; + ll?: string; + lll?: string; + llll?: string; + lt?: string; + +} + +interface MomentRelativeTime { + + future: any; + past: any; + s: any; + m: any; + mm: any; + h: any; + hh: any; + d: any; + dd: any; + M: any; + MM: any; + y: any; + yy: any; + +} interface MomentStatic { @@ -146,7 +203,7 @@ interface MomentStatic { isMoment(): bool; isMoment(m: any): bool; lang(language: string); - lang(language: string, definition: any); // TODO definition + lang(language: string, definition: MomentLanguage); months: string[]; monthsShort: string[]; weekdays: string[]; @@ -154,7 +211,7 @@ interface MomentStatic { weekdaysMin: string[]; longDateFormat: any; relativeTime: any; - meridiem: (hour, minute, isLower) => string; + meridiem: (hour: number, minute: number, isLowercase: bool) => string; calendar: any; ordinal: (num: number) => string; @@ -165,4 +222,4 @@ interface MomentStatic { duration(): Duration; } -declare var moment: MomentStatic; \ No newline at end of file +declare var moment: MomentStatic;