secret
Last active

Moment.js 2.0.0 release notes

  • Download Gist
moment.2.0.0.changelog.md
Markdown

New Features

Added short form localized tokens.

We added 4 new formatting tokens. l ll lll llll. These tokens are the the shorter counterparts to the uppercase L tokens.

The same units exist in both formats. Choosing between an ordinal, zero filled, or plain number will depend on whether the format is uppercase or lowercase L. The same consideration should be made between long form names and abbreviated names.

moment().format('L'); // 01/14/2013
moment().format('l'); // 1/14/2013
moment().format('LL'); // January 14th 2013
moment().format('ll'); // Jan 14 2013
moment().format('LLL'); // January 14th 2013 2:08 PM
moment().format('lll'); // Jan 14 2013 2:08 PM
moment().format('LLLL'); // Monday, January 14th 2013 2:08 PM
moment().format('llll'); // Mon, Jan 14 2013 2:08 PM

The number of characters defines which types of tokens are used.

1    L/l     Month numeral, day of month, year
2   LL/ll    Month name, day of month, year
3  LLL/lll   Month name, day of month, year, time
4 LLLL/llll  Month name, day of month, day of week, year, time

Added ability to define language a string should be parsed in.

https://github.com/timrwood/moment/pull/574

If a language has been loaded into moment.js, you can now specify the language that the moment should be parsed in.

// before
moment.lang('fr');
var a = moment('2012 juillet', 'YYYY MMM');
moment.lang('en');
var b = moment('2012 July', 'YYYY MMM');
// after
var a = moment('2012 juillet', 'YYYY MMM', 'fr');
var b = moment('2012 July', 'YYYY MMM', 'en');

Added support for reversed add/subtract arguments.

Due to inverted syntax between moment#add(string, number) and moment.duration(number, string), we added support for reversing the arguments in add and subtract.

The following syntaxes are now supported.

moment().add({seconds:1});
moment().add('seconds', 1);
moment().add('seconds', '1');
moment().add(1, 'seconds');

Due to implementation details, the following syntax is not supported. The first argument should be typecast to a number in this instance.

moment().add('1', 'seconds');

Added support for endOf('week') and startOf('week').

These set the moment to the beginning or end of the week. The first day of the week is Sunday.

Fixed the logic for moment#diff(Moment, 'months') and moment#diff(Moment, 'years').

https://github.com/timrwood/moment/pull/571

Because the most common use case for month and year diffs is birthday calculation and age gating, the difference calculation has been optimized for comparing two moments with the same day of the month.

Jan 15 to Feb 15 is exactly 1 month. Feb 28 to Mar 28 is exactly 1 month. Feb 28 2011 to Feb 28 2012 is exactly 1 year.

The values for different moments without the same day of the month are also as expected.

Jan 31 to Feb 28 is slightly less than 1 month. Jan 31 to Mar 1 is slightly more than 1 month.

The implimentation details can be seen here: https://github.com/timrwood/moment/pull/571#issuecomment-12282754

moment#diff now floors instead of rounds

moment([2012, 0, 1]).diff([2012, 0, 1], 'months'); // 0
moment([2012, 0, 1]).diff([2012, 0, 31], 'months'); // 0
moment([2012, 0, 1]).diff([2012, 1, 1], 'months'); // 1
moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true); // .9677
moment([2012, 0, 1, 0]).diff([2012, 0, 1, 23], 'days'); // 0
moment([2012, 0, 1, 0]).diff([2012, 0, 1, 23], 'days', true); // .9583

Normalized moment#toString.

Calling moment().toString() is now equivalent to moment().format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ") in order to normalize behavior across environments.

Added isSame, isAfter, isBefore methods.

These three new methods all accept a units parameter of any string that can be used in startOf or endOf.

They return a boolean as you would expect from their method names.

moment().isBefore(otherMoment);
moment().isAfter(otherMoment, 'day');
moment().isSame(otherMoment, 'month');

Added week support

https://github.com/timrwood/moment/pull/503

We added a getter/setter for week and for isoWeek. The week getter/setter uses the moment's language config to determine which day starts the week, and which week starts the year. The isoWeek getter/setter uses the ISO week numbering.

The W WW Wo tokens have also been added, which display the iso week number. The w ww wo tokens now use the week getter/setters, and thus use the language settings for which week numbering system to use.

The dayOfYear getter/setter method was also added in support of the weeks addition.

Added moment#toJSON

https://github.com/timrwood/moment/pull/444

Now, when exporting a moment with JSON.stringify, the moment will be represented as a string with the format 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'.

This is in line with the implementation of Date#toJSON in environments that support it.

Switched to grunt for development tasks

Because that's what cool kids do.

Bugfixes

Fixed parsing of first century dates

https://github.com/timrwood/moment/pull/367

Parsing 10Sep2001 should work as expected

https://github.com/timrwood/moment/issues/470

Fixed some wierdness with moment.utc() parsing

https://github.com/timrwood/moment/issues/528

Backwards incompatible changes

Changed language ordinal method to return the number + ordinal instead of just the ordinal.

https://github.com/timrwood/moment/pull/577

In order to better support internationalization, the ordinal method now requires that you return the number and the ordinal instead of simply the ordinal. This allows languages to eliminate the number altogether if needed.

Additionally, if you set the ordinal property to a string, the first %d in the string will be replaced with the number to be ordinalized.

Changed two digit year parsing cutoff to match strptime

https://github.com/timrwood/moment/issues/468

Before, '70 = 2070 and '71 = 1971. Now, '68 = 2068 and '69 = 1969.

Removed moment#sod and moment#eod in favor of moment#startOf and moment#endOf

https://github.com/timrwood/moment/pull/283

Removed moment.humanizeDuration() in favor of moment.duration().humanize()

https://github.com/timrwood/moment/pull/572

Removed the lang data objects from the top level namespace.

https://github.com/timrwood/moment/issues/334

Now, to get the lang data, use moment.langData() for the global language, or better yet, moment#lang() for the instance language.

Duplicate Date passed to moment() instead of referencing it.

https://github.com/timrwood/moment/issues/592

Now, a preexisting date passed in to moment() does not get referenced. Instead, a new Date is created with the value of the date passed in.

var d = new Date();
var m = moment(d);
// m._d !== d

New Languages

  • Arabic (ar)
  • Moroccan Arabic (ar-ma)
  • Czech (cs)
  • Esperanto (eo)
  • Hebrew (he)
  • Bahasa Indonesia (id)
  • Latvian (lv)
  • Nepalese (ne)
  • Slovenian (sl)
  • Thai (th)
  • Morocco Central Atlas Tamazi╔út in Latin (tzm-la)
  • Morocco Central Atlas Tamazi╔út (tzm)
  • Ukrainian (uk)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.