mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
1fe51ef586
Summary: - Setting the locale in moment was not sufficient to actually use the correct localized formats. - Moment provides localized format via the formats : 'L', 'LL', 'll', etc. See: http://momentjs.com/docs/#/displaying/format/ - Updates to set our date formats based on localized formats: - Unfortunately, localized formats always contain the year, so I manually removed the year from our short format. - Actually fixes: #1515 - Fixes bug where setting nextWeek or thisWeekend returned incorrect date if the current day was saturday or sunday - Add specs Test Plan: Unit tests Reviewers: evan, drew, bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D2688
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
import moment from 'moment'
|
|
import {DateUtils} from 'nylas-exports'
|
|
|
|
|
|
describe('DateUtils', ()=> {
|
|
describe('nextWeek', ()=> {
|
|
it('returns tomorrow if now is sunday', ()=> {
|
|
const sunday = moment("03-06-2016", "MM-DD-YYYY")
|
|
const nextWeek = DateUtils.nextWeek(sunday)
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-07-2016')
|
|
});
|
|
|
|
it('returns next monday if now is monday', ()=> {
|
|
const monday = moment("03-07-2016", "MM-DD-YYYY")
|
|
const nextWeek = DateUtils.nextWeek(monday)
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-14-2016')
|
|
});
|
|
|
|
it('returns next monday', ()=> {
|
|
const saturday = moment("03-05-2016", "MM-DD-YYYY")
|
|
const nextWeek = DateUtils.nextWeek(saturday)
|
|
expect(nextWeek.format('MM-DD-YYYY')).toEqual('03-07-2016')
|
|
});
|
|
});
|
|
|
|
describe('thisWeekend', ()=> {
|
|
it('returns tomorrow if now is friday', ()=> {
|
|
const friday = moment("03-04-2016", "MM-DD-YYYY")
|
|
const thisWeekend = DateUtils.thisWeekend(friday)
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-05-2016')
|
|
});
|
|
|
|
it('returns next saturday if now is saturday', ()=> {
|
|
const saturday = moment("03-05-2016", "MM-DD-YYYY")
|
|
const thisWeekend = DateUtils.thisWeekend(saturday)
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-12-2016')
|
|
});
|
|
|
|
it('returns next saturday', ()=> {
|
|
const sunday = moment("03-06-2016", "MM-DD-YYYY")
|
|
const thisWeekend = DateUtils.thisWeekend(sunday)
|
|
expect(thisWeekend.format('MM-DD-YYYY')).toEqual('03-12-2016')
|
|
});
|
|
});
|
|
});
|