Permalink
Browse files

Add definitions for moment language customizations per issue #182.

  • Loading branch information...
1 parent dfb53f8 commit 04517266de7fffd4469227819a887ebf13002341 @seanski seanski committed Feb 15, 2013
Showing with 212 additions and 5 deletions.
  1. +151 −1 moment/moment-tests.ts
  2. +61 −4 moment/moment.d.ts
View
@@ -228,4 +228,154 @@ moment.duration(500).asMilliseconds();
moment.duration(500).seconds();
moment.duration(500).asSeconds();
moment.duration().minutes();
-moment.duration().asMinutes();
+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;
+ }
+});
View
@@ -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,15 +203,15 @@ 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[];
weekdaysShort: string[];
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;
+declare var moment: MomentStatic;

0 comments on commit 0451726

Please sign in to comment.