From: Tim Wood Date: Mon, 17 Oct 2011 19:58:01 +0000 (-0700) Subject: Finishing docs and updating readme for 1.0.0 release X-Git-Tag: 1.0.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e8b857e492b907da13e4bfd92abb68d73c55715;p=thirdparty%2Fmoment.git Finishing docs and updating readme for 1.0.0 release --- diff --git a/README.markdown b/README.markdown index 606b105ff..cdf90e622 100755 --- a/README.markdown +++ b/README.markdown @@ -1,697 +1,20 @@ -Moment -====== +Moment.js +========= -Moment is a javascript date library that helps create, manipulate, and format dates without extending the `Date` prototype. +Moment.js is a javascript date library that helps create, manipulate, and format dates without extending the `Date` prototype. Author: Tim Wood -Version: 0.7.0 +Version: 1.0.0 ### 2.2 kb (min + gzip) -Where to use it -=============== - -### Node.js - -Install with npm - npm install underscore.date -Usage - - var _date = require('underscore.date'); - console.log(_date('September 9 1999').fromNow()); - -### In the browser - -If underscore exists, underscore.date will mix itself into the underscore namespace, so you can use as you would use an underscore function. - - _.date('September 9 1999').fromNow(); - -Otherwise, you should use `_date`. - - _date('September 9 1999').fromNow(); - -_date() -======= - -The library works by creating a `_date()` wrapper object. To create that wrapper, you can pass any of the following data types in. - - - -### Number - - _date(1300291340510) - -An integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC. - - - -### Date - - _date(new Date(2010, 1, 14, 15, 25, 50, 125)) - -Any valid `Date` object. For more information on `Date` objects, see [the JavaScript Date documentation at MDN](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) - - - - -### Array - - _date([2010, 1, 14, 15, 25, 50, 125]) - -An array mirroring the parameters passed into [Date.UTC()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/UTC). - -`[year, month = 0, date = 1, hours = 0, minutes = 0, seconds = 0, milliseconds = 0]` - -Any value past the year is optional, and will default to the lowest possible number. - - - -### undefined - - _date() - -If no value is passed to a 'dateInput' parameter, it will default to the current time using `new Date()`. - - _date() === _date(new Date()) - - - - -### String - - _date("Dec 25, 1995") - -A string that can be parsed by [Date.parse()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/parse). - - - -### String with format - - _date("12-25-1995", "MM-DD-YYYY") - -A string and a format string. The second string will be used as the format to parse the first string. - -The format parts are similar to the formats from _date().format() - -**Important:** Parsing a string with a format is by far the slowest method of creating a date. -If you have the ability to change the input, it is much faster (~15x) to use Unix timestamps. - -NOTE: The parser ignores non-alphanumeric characters, so both `_date("12-25-1995", "MM-DD-YYYY")` and -`_date("12\25\1995", "MM-DD-YYYY")` will return the same thing. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
InputOutput
M or MMMonth
D or DDDay of month
DDD or DDDDDay of year
YY2 digit year (if greater than 70, will return 1900's, else 2000's)
YYYY4 digit year
a or AAM/PM
H, HH, h, or hh24 hour (for 12 hour time, use in conjunction with a or A)
m or mmMinutes
s or ssSeconds
- - -### String with array of formats - - _date("12-25-1995", ["MM-DD-YYYY", "YYYY-MM-DD"]) - -A list of format strings to try to parse the input string. - -This will find the format that is closest to the input formats. This is fundamentally problematic in cases like the following. - - _date("05-06-1995", ["MM-DD-YYYY", "DD-MM-YYYY"]) // June 5th or May 6th? - -Ideally, you should stick to one input format for creating dates. - -**Important:** THIS IS SLOW. This should only be used as a last line of defense. Check out the comparisons at -http://jsperf.com/underscore-date/2 if you don't believe me. It's the one on the bar graph that you can't even see, that's -how slow it is. - -_date Prototype -=============== - -`underscore.date` contains a number of utility functions for manipulating and formatting dates. - - -_date.add() ------------ - - _date.add(object) - -Adds time per the object passed in. - -The object should have key value pairs as shown below. - - { - ms : 200, // milliseconds - s : 10, // seconds - m : 10, // minutes (note: lowercase) - h : 2, // hours - d : 3, // days - M : 2, // months (note: uppercase) - y : 3 // years - } - -All the parameters are optional. Also, there are no upper limits for the values, so you can overload any of the parameters. - - { ms : 1000000 } // a million milliseconds - { d : 360 } // 360 days - -### Special considerations for months and years - -If the day of the month on the original date is greater than the number of days in the final month, the day of the month will change to the last day in the final month. - -Example: - - _date([2010, 0, 31]) // January 31 - _date([2010, 0, 31]).add({M : 1}) // February 28 - - -_date.subtract() ----------------- - - _date.subtract(object) - -Functions the same as `_date.add()`, only using subtraction instead of addition. - -Example: - - _date([2010, 1, 28]) // February 28 - _date([2010, 1, 28]).subtract({M:1}) // January 28 - - - -_date.format() --------------- - - _date.format(string) - -Returns a human readable string based on the format string that was passed in. - - var dateToFormat = new Date(2010, 1, 14, 15, 25, 50, 125); - _date(dateToFormat).format("dddd, MMMM Do YYYY, h:mm:ss a"); // "Sunday, February 14th 2010, 3:25:50 pm" - _date(dateToFormat).format("ddd, hA"); // "Sun, 3PM" - -The formats are created by creating a string of replacable characters. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
InputOutput
Month
M1 2 ... 11 12
Mo1st 2nd ... 11th 12th
MM01 02 ... 11 12
MMMJan Feb ... Nov Dec
MMMMJanuary February ... November December
Day of Month
D1 2 ... 30 30
Do1st 2nd ... 30th 31st
DD01 02 ... 30 31
Day of Year
DDD1 2 ... 364 365
DDDo1st 2nd ... 364th 365th
DDDD001 002 ... 364 365
Day of Week
d0 1 ... 5 6
do0th 1st ... 5th 6th
dddSun Mon ... Fri Sat
ddddSunday Monday ... Friday Saturday
Week of Year
w1 2 ... 52 53
wo1st 2nd ... 52nd 53rd
ww01 02 ... 52 53
Year
YY70 71 ... 29 30
YYYY1970 1971 ... 2029 2030
AM/PM
AAM PM
aam pm
Hour
H0 1 ... 22 23
HH00 01 ... 22 23
h1 2 ... 11 12
hh01 02 ... 11 12
Minute
m0 1 ... 58 59
mm00 01 ... 58 59
Second
s0 1 ... 58 59
ss00 01 ... 58 59
Timezone
zEST CST ... MST PST
zz - Eastern Standard Time ... Pacific Standard Time

- - NOTE: Internet Explorer uses a different implementation of - Date.toString(), so we are unable to retrieve the full string - of the timezone, and will fall back to 'z'.

- So:
- Firefox, Chrome, Safari, etc. == 'Eastern Standard Time'
- Internet Explorer, etc. == 'EST' -
-
- - - -_date.from() ------------- - - _date.from(date, withoutSuffix:boolean, asMilliseconds:boolean) - -Returns a string as relative time ('minutes ago', '5 months ago', etc). - -You can pass anything that you would pass to _date() as the first parameter, or a `_date()` object. - - _date([2007, 0, 29]).from(_date([2007, 0, 28])) // "a day ago" - -You can pass `true` as the second parameter to return without the prefixes and suffixes. - - _date([2007, 0, 29]).from(_date([2007, 0, 28]), true) // "a day" - -You can pass `true` as the third parameter to return as milliseconds. -The number of milliseconds returned will be positive if the date passed -in is later than the first date, and negative if the date passed in is earlier. - - _date([2007, 0, 29]).from(_date([2007, 0, 28]), true , true) // -86400000); - _date([2007, 0, 27]).from(_date([2007, 0, 28]), true , true) // 86400000); - -The base strings for this function can be customized with `_date.relativeTime`. - -The breakdown of which string is displayed when is outlined in the table below. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
RangeKeySample Output
0 to 45 secondssseconds ago
45 to 90 secondsma minute ago
90 seconds to 45 minutesmm2 minutes ago ... 45 minutes ago
45 to 90 minuteshan hour ago
90 minutes to 22 hours hh2 hours ago ... 22 hours ago
22 to 36 hoursda day ago
36 hours to 25 daysdd2 days ago ... 25 days ago
25 to 45 daysMa month ago
45 to 345 daysMM2 months ago ... 11 months ago
345 to 547 days (1.5 years)ya year ago
548 days+yy2 years ago ... 20 years ago
- - -_date.fromNow() ---------------- - - _date.fromNow(withoutSuffix:boolean, asMilliseconds:boolean) - -Retuns the time from now. - -A shortcut for `_date.from(_date(), withoutSuffix:boolean, asMilliseconds:boolean)`. - - -_date.isLeapYear() ------------------- - -Returns `true` if the year is a leap year, `false` if it is not - -Examples : - - _date([2000]).isLeapYear() // true - _date([2001]).isLeapYear() // false - _date([2100]).isLeapYear() // false - - -Localization and Customization -============================== - -_date.lang() ------------- - -Add or switch a language. - -To add a language, pass in the language key and the language constants. _date will cache the language based on the key for reuse. - - _date.lang('pt', { - months : ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"], - monthsShort : ["Jan", "Feb", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"], - weekdays : ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"], - weekdaysShort : ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"], - relativeTime : { - future: "em %s", - past: "%s atrás", - s: "segundos", - m: "um minuto", - mm: "%d minutos", - h: "uma hora", - hh: "%d horas", - d: "um dia", - dd: "%d dias", - M: "um mês", - MM: "%d meses", - y: "um ano", - yy: "%d anos" - }, - ordinal : function (number) { - return 'º'; - }, - } - -Once a language has been set, all `_date.format` and `_date.from` calls will use that language. To change to another language, -call `_date.lang('otherlang', { months : [] ... })`. - -Once a language has been cached, you can simply call the key to retrieve it from the cache. This allows for easily switching -between multiple languages. - - _date.lang('pt'); - _date(1316116057189).fromNow() // uma hora atrás - _date.lang('en'); - _date(1316116057189).fromNow() // an hour ago - -There are languages in the `./underderscore.date.lang/` folder. You can `require()` them or add them to your page in the browser. - -### Node - - var _date = require('underscore.date.js') - var testLang = require('underscore.date.lang/test.js'); - _date.lang(testLang.abbr, testLang.lang); - -### Browser - - - -NOTE: The language should be included after underscore.date, and will automatically switch to that language. -To switch back to english, just use `_date.lang('en')` as that language is provided by default. - -Ad Hoc customization --------------------- - -If you want to customize the wording of `_date.format()` and `_date.from()`, but don't want to create an entire language object, -the strings are exposed through the _date object. You can modify these however you see fit. However, calls to `_date.lang` will overwrite them. - -Examples : - - _date.relativeTime.future = "%s from now"; - _date.relativeTime.past = "%s in the past"; - -_date.relativeTime ------------------- - - _date.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" - }; - -The strings used in `_date.from()`. - -`future` and `past` are used as the suffixes/prefixes. - -For all these values, a single character refers to the singular, and an double character refers to the plural. - -_date.weekdays --------------- - - _date.weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - -An array of day names, starting with Sunday. - -_date.weekdaysShort -------------------- - - _date.weekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - -An array of abbreviated day names, starting with Sunday. - -_date.months ------------- - - _date.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - -An array of the names of the months, starting with January. - -_date.monthsShort ------------------ - - _date.monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; - -An array of the abbreviated names of the months, starting with January. - -_date.ordinal -------------- - - _date.ordinal = function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }; - -A function that returns a string to be appended to the number passed in. -[More information on ordinal numbers](http://en.wikipedia.org/wiki/Ordinal_number_%28linguistics%29) - - - -Tests -===== - -### Unit tests - -[Underscore.date unit tests](http://timrwood.github.com/underscore.date/test/test.html) - -[Underscore.date performance tests](http://jsperf.com/underscore-date) - -The unit tests can also be run in node by running `node test.js` on the root folder. - - -### Speed tests -[Floor vs bitwiseor vs bitwisenor vs parseint](http://jsperf.com/floor-vs-bitwise-or-vs-parseint/4) - -[Switch/case vs object of functions lookup](http://jsperf.com/object-of-functions-vs-switch) +Documentation +============= -[Left zero filling](http://jsperf.com/left-zero-filling) +Read the documentation at [momentjs.com/docs](http://momentjs.com/docs). Thanks to... ============ @@ -705,17 +28,17 @@ Everyone who helped with [php.js date](http://phpjs.org/functions/date:380). License ======= -Moment is freely distributable under the terms of the MIT license. +Moment.js is freely distributable under the terms of the MIT license. Changelog ========= -### 0.7.0 +### 1.0.0 Added convenience methods for getting and setting date parts Added better support for `moment.add()` Added better lang support in node -Renamed library from underscore.date to moment +Renamed library from underscore.date to Moment.js ### 0.6.1 diff --git a/build.js b/build.js index f7fc8917a..4c827b907 100755 --- a/build.js +++ b/build.js @@ -38,8 +38,8 @@ var JSHINT_CONFIG = { var LANG_MINIFY = "fr it pt".split(" "); var LANG_TEST = "en fr it pt".split(" "); var LANG_PREFIX = "var moment;if (typeof window === 'undefined') {moment = require('../moment.js');module = QUnit.module;}"; -var VERSION = '0.7.0'; -var MINIFY_COMMENT = '/* moment | version : ' + VERSION + ' | author : Tim Wood | license : MIT */\n'; +var VERSION = '1.0.0'; +var MINIFY_COMMENT = '/* Moment.js | version : ' + VERSION + ' | author : Tim Wood | license : MIT */\n'; /********************************************* diff --git a/docs/index.html b/docs/index.html index 4accee727..ef59511d8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -44,9 +44,9 @@
  • Formatted date
  • Time from another moment
  • Time from now
  • +
  • Difference
  • Native Date
  • -
  • valueOf
  • -
  • Diff
  • +
  • Value
  • Seconds
  • Minutes
  • Hours
  • @@ -60,6 +60,16 @@
  • Changing languages
  • Loading languages in NodeJS
  • Loading languages in the browser
  • +
  • Adding your language to Moment.js
  • + +

    Customization

    +
    @@ -68,10 +78,10 @@

    Github

    - Development Version (0.7.0) 20k Source + Comments + Development Version (1.0.0) 20k Source + Comments

    - Production Version (0.7.0) 2.2k Minified + Gzipped. + Production Version (1.0.0) 2.2k Minified + Gzipped.

    You can also clone the project with Git by running:

    $ git clone git://github.com/timrwood/moment
    @@ -94,13 +104,14 @@ moment().add('hours', 1).fromNow(); // "1 hour ago"

    In the browser

    -<script src="moment.js"></script>
    +<script src="moment.min.js"></script>
     moment().add('hours', 1).fromNow(); // "1 hour ago"
     

    Parsing

    -

    Instead of modifying the native Date.prototype, Moment.js creates a wrapper for the Date object

    +

    Instead of modifying the native Date.prototype, Moment.js creates a wrapper for the Date object.

    +

    Note: The Moment.js prototype is exposed through moment.fn. If you want to add your own functions, that is where you would put them.

    To get this wrapper object, simply call moment() with one of the supported input types

    Javascript Date Object

    @@ -373,7 +384,7 @@ moment().year(1984); // set the year to 1984

    Display

    Once parsing and manipulation are done, you need some way to display the moment. Moment.js offers many ways of doing that.

    -

    Formatted Date

    +

    Formatted Date

    The most robust display option is moment.fn.format. It takes a string of tokens and replaces them with their corresponding values from the Date object.

    @@ -557,13 +568,32 @@ moment(date).format("ddd, hA");                       // "Sun, 3PM"
                     
                 
                 
    -            

    Time from another moment

    +

    Time from another moment

    Another common way of displaying time, sometimes called timeago, is handled by moment.fn.from.

     var a = moment([2007, 0, 29]);
     var b = moment([2007, 0, 28]);
     a.from(b) // "a day ago"
    +
    +

    +

    The first parameter is anything you can pass to moment() or a Moment.js object.

    +

    +

    +var a = moment([2007, 0, 29]);
    +var b = moment([2007, 0, 28]);
    +a.from(b);                     // "a day ago"
    +a.from([2007, 0, 28]);         // "a day ago"
    +a.from(new Date(2007, 0, 28)); // "a day ago"
    +a.from("1-28-2007");           // "a day ago"
    +
    +

    +

    NOTE: Because it only accepts one parameter to pass in the date info, if you need to use String + Format or String + Formats, you should create a Moment.js object first and then call moment.fn.from

    +

    +

    +var a = moment();
    +var b = moment("10-10-1900", "MM-DD-YYYY");
    +a.from(b);
     

    If you pass true as the second parameter, you can get the value without the suffix. This is useful wherever you need to have a human readable length of time.

    @@ -571,7 +601,7 @@ a.from(b) // "a day ago"
     var start = moment([2007, 0, 5]);
     var end = moment([2007, 0, 10]);
    -start.from(end); // "in 5 days"
    +start.from(end);       // "in 5 days"
     start.from(end, true); // "5 days"
     

    @@ -640,7 +670,7 @@ start.from(end, true); // "5 days" -

    Time from now

    +

    Time from now

    This is just a map to moment.fn.from(new Date())

    @@ -650,10 +680,250 @@ moment([2007, 0, 29]).fromNow(); // 4 years ago
                 

    Like moment.fn.from, if you pass true as the second parameter, you can get the value without the suffix.

    -moment([2007, 0, 29]).fromNow(); // 4 years ago
    +moment([2007, 0, 29]).fromNow();     // 4 years ago
     moment([2007, 0, 29]).fromNow(true); // 4 years
     

    + +

    Difference

    +

    To get the difference in milliseconds, use moment.fn.diff like you would use moment.fn.from.

    +

    +

    +var a = moment([2007, 0, 29]);
    +var b = moment([2007, 0, 28]);
    +a.diff(b) // 86400000
    +
    +

    + +

    Native Date

    +

    To get the native Date object that Moment.js wraps, use moment.fn.native.

    +

    +

    +var a = moment([2007, 0, 29]);
    +var b = moment([2007, 0, 28]);
    +a.diff(b) // 86400000
    +
    +

    + +

    Value

    +

    moment.fn.valueOf simply outputs the unix timestamp.

    +

    +

    +moment(1318874398806).valueOf(); // 1318874398806
    +
    +

    + +

    Seconds

    +

    These are the getters mentioned in the Manipulation section above.

    +

    These map to the corresponding function on the native Date object.

    +

    +

    +moment().seconds() === new Date().getSeconds();
    +
    +

    + +

    Minutes

    +

    +

    +moment().minutes(); // get the minutes
    +
    +

    + +

    Hours

    +

    +

    +moment().hours(); // get the hours
    +
    +

    + +

    Day

    +

    +

    +moment().day(); // get the day 
    +
    +

    + +

    Month

    +

    +

    +moment().month(); // get the month
    +
    +

    + +

    Year

    +

    +

    +moment().year(); // get the year
    +
    +

    + +

    Leap Year

    +

    moment.fn.isLeapYear returns true if that year is a leap year, and false if it is not.

    +

    +

    +moment([2000]).isLeapYear() // true
    +moment([2001]).isLeapYear() // false
    +moment([2100]).isLeapYear() // false
    +
    +

    + +

    I18N

    +

    Moment.js has pretty robust support for internationalization. You can load multiple languages onto the same instance and easily switch between them.

    + +

    Changing languages

    +

    By default, Moment.js comes with English language strings. If you need other languages, you can load them into Moment.js for later use.

    +

    To load a language, pass the key and the string values to moment.lang.

    +

    Note: More details on each of the parts of the language bundle can be found in the customization section.

    +

    +

    +moment.lang('fr', {
    +    months : "Janvier_Février_Mars_Avril_Mai_Juin_Juillet_Aout_Septembre_Octobre_Novembre_Décembre".split("_"),
    +    monthsShort : "Jan_Fev_Mar_Avr_Mai_Juin_Juil_Aou_Sep_Oct_Nov_Dec".split("_"),
    +    weekdays : "Dimanche_Lundi_Mardi_Mercredi_Jeudi_Vendredi_Samedi".split("_"),
    +    weekdaysShort : "Dim_Lun_Mar_Mer_Jeu_Ven_Sam".split("_"),
    +    relativeTime : {
    +        future : "in %s",
    +        past : "il y a %s",
    +        s : "secondes",
    +        m : "une minute",
    +        mm : "%d minutes",
    +        h : "une heure",
    +        hh : "%d heures",
    +        d : "un jour",
    +        dd : "%d jours",
    +        M : "un mois",
    +        MM : "%d mois",
    +        y : "une année",
    +        yy : "%d années"
    +    },
    +    ordinal : function (number) {
    +        return (~~ (number % 100 / 10) === 1) ? 'er' : 'ème';
    +    }
    +});
    +
    +

    +

    Once you load a language, it becomes the active language. To change active languages, simply call moment.lang with the key of a loaded language.

    +

    +

    +moment.lang('fr');
    +moment(1316116057189).fromNow() // il y a une heure
    +moment.lang('en');
    +moment(1316116057189).fromNow() // an hour ago
    +
    +

    + +

    Loading languages in NodeJS

    +

    Loading languages in NodeJS is super easy. If there is a language file in moment/lang/ named after that key, the first call to moment.lang will load it.

    +

    +

    +var moment = require('moment');
    +moment.lang('fr');
    +moment(1316116057189).fromNow(); // il y a une heure
    +
    +

    +

    Right now, there is only support for English, French, Italian, and Portuguese. If you want your language supported, create a pull request or send me an email with the required files.

    + +

    Loading languages in the browser

    +

    Loading languages in the browser just requires you to include the language files.

    +

    +

    +<script src="moment.min.js"></script>
    +<script src="lang/fr.js"></script>
    +<script src="lang/pt.js"></script>
    +
    +

    +

    There are minified versions of each of these languages. There is also a minified version of all of the languages bundled together.

    +

    +

    +<script src="moment.min.js"></script>
    +<script src="lang/all.min.js"></script>
    +
    +

    +

    Ideally, you would bundle all the files you need into one file to minimize http requests.

    +

    +

    +<script src="moment-fr-it.min.js"></script>
    +
    +

    + +

    Adding your language to Moment.js

    +

    To add your language to Moment.js, submit a pull request with both a language file and a test file. You can find examples in moment/lang/fr.js and moment/test/lang/fr.js

    +

    To run the tests, do node build.

    +

    If there are no errors building, then do node test or open moment/test/index.html.

    +

    If all the tests pass, submit that pull request, and thank you for contributing!

    + +

    Customization

    +

    If you don't need i18n support, you can manually override the customization values. However, any calls to moment.lang will override them. It is probably safer to create a language for your specific customizations than to override these values manually.

    + +

    Month Names

    +

    moment.months should be an array of the month names.

    +

    +

    +moment.months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    +
    +

    + +

    Month Abbreviations

    +

    moment.monthsShort should be an array of the month abbreviations.

    +

    +

    +moment.monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    +
    +

    + +

    Weekday Names

    +

    moment.weekdays should be an array of the weekdays names.

    +

    +

    +moment.weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    +
    +

    + +

    Weekday Abbreviations

    +

    moment.weekdaysShort should be an array of the weekdays abbreviations.

    +

    +

    +moment.weekdaysShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    +
    +

    + +

    Relative Time

    +

    moment.relativeTime should be an object of the replacement strings for moment.fn.from.

    +

    +

    +moment.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"
    +};
    +
    +

    +

    future refers to the prefix/suffix for future dates, and past refers to the prefix/suffix for past dates. For all others, a single character refers to the singular, and an double character refers to the plural.

    + +

    Ordinal

    +

    moment.ordinal should be a function that returns the ordinal for a given number.

    +

    +

    +moment.ordinal = function (number) {
    +    var b = number % 10;
    +    return (~~ (number % 100 / 10) === 1) ? 'th' : 
    +        (b === 1) ? 'st' : 
    +        (b === 2) ? 'nd' : 
    +        (b === 3) ? 'rd' : 'th';
    +};
    +
    +

    +

    For more information on ordinal numbers, see wikipedia

    diff --git a/moment.js b/moment.js index b214fdd6f..b72c13f97 100644 --- a/moment.js +++ b/moment.js @@ -1,9 +1,9 @@ -// Underscore.date +// Moment.js // // (c) 2011 Tim Wood -// Underscore.date is freely distributable under the terms of the MIT license. +// Moment.js is freely distributable under the terms of the MIT license. // -// Version 0.6.1 +// Version 1.0.0 (function (Date, undefined) { diff --git a/moment.min.js b/moment.min.js index fa7dfcede..03483503d 100755 --- a/moment.min.js +++ b/moment.min.js @@ -1,2 +1,2 @@ -/* moment | version : 0.7.0 | author : Tim Wood | license : MIT */ +/* Moment.js | version : 1.0.0 | author : Tim Wood | license : MIT */ (function(a,b){function j(a,b){var c=a+"";while(c.length11?"pm":"am";case"A":return i>11?"PM":"AM";case"H":return i;case"HH":return j(i,2);case"h":return i%12||12;case"hh":return j(i%12||12,2);case"m":return k;case"mm":return j(k,2);case"s":return l;case"ss":return j(l,2);case"zz":case"z":return(b.toString().match(o)||[""])[0].replace(n,"");default:return d.replace("\\","")}}var e=b.getMonth(),f=b.getDate(),g=b.getFullYear(),h=b.getDay(),i=b.getHours(),k=b.getMinutes(),l=b.getSeconds(),m=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?)/g,n=/[^A-Z]/g,o=/\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g;return d.replace(m,p)}function o(a,b){function i(a,b){switch(a){case"M":case"MM":c[1]=~~b-1;break;case"D":case"DD":case"DDD":case"DDDD":c[2]=~~b;break;case"YY":b=~~b,c[0]=b+(b>70?1900:2e3);break;case"YYYY":c[0]=~~b;break;case"a":case"A":h=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b}}var c=[0],d=/[0-9a-zA-Z]+/g,e=a.match(d),f=b.match(d),g,h;for(g=0;g