Mailspring/spec/utils/date-utils-spec.es6

174 lines
5.8 KiB
Plaintext
Raw Normal View History

import moment from 'moment'
import {DateUtils} from 'nylas-exports'
describe('DateUtils', function dateUtils() {
2016-05-06 13:30:34 +08:00
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')
});
2016-05-06 13:30:34 +08:00
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')
});
2016-05-06 13:30:34 +08:00
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')
});
});
2016-05-06 13:30:34 +08:00
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')
});
2016-05-06 13:30:34 +08:00
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')
});
2016-05-06 13:30:34 +08:00
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')
});
});
Better support 24-hour time (#2622) * Added support for 24-hour time to the thread list view (Issue #682) * Add 24-hour time support to the thread list scroll tooltip (Issue #682) * Fix for 24-hour time in the thread list scroll tooltip (#682) Correctly imports the DateUtils module * Add support for 24-hour time to the draft threads list (Issue #682) * Add 24-hour time to the message sidebar * Fix for 24-hour time in the message view so the rollover tooltip is 24hour also (#682) * Removed unused date functions from utils fullTimeString and shortTimeString from src/flux/models/utils.coffee were not compatible with 24-hour time. These functions were modified and moved to DateUtils in src/date-utils. * Fix for display of 24-hour time in the message view (Issue #682) * Removed unused import of Utils in a couple of files Prompted by Travis build errors. * Updates to handling of date/time display Incorporates changes suggested by @bengotow. Re-enables support for the isDetailed property in message-timestamp (if this is set to true, a medium length date/time string will be used for display). Re-enables additional display varieties based on when the email was received. Note that this is implemented slightly different to the orinal version - time is now given as an absolute time rather than "... days ago" format. TZ guessing moved to the global scope of date-utils for performance reasons. * Minor de-linting * Re-enable all tests by unfocusing the test suite A previous commit (ad04775) added an fdescribe() to one of the tests in draft-helpers-spec. This changes that to a regular describe() so that all tests will be run when running ./N1 --test. * Added tests for the new DateUtils functions Added tests for getTimeFormat, mediumTimeString and fullTimeString. Removed no longer relevant tests from message-timestamp-spec as _formattedDate has been removed in favour of the functions in date-utils. To test shortTimeString, we need to be able to set a fake current time which is possible in jasmine 2.0+ but not in 1.3 which is currently in use. As a possible bug, when running more than 10 tests the following warning is raised: "(node:25025) Warning: Possible EventEmitter memory leak detected. 11 on-config-reloaded listeners added. Use emitter.setMaxListeners() to increase limit", source: internal/process/warning.js (24) * Minor de-linting
2016-07-29 08:42:14 +08:00
describe('getTimeFormat: 12-hour clock', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(false)
});
it('displays the time format for a 12-hour clock', () => {
const time = DateUtils.getTimeFormat(null)
expect(time).toBe('h:mm a')
});
it('displays the time format for a 12-hour clock with timezone', () => {
const opts = { timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm a z')
});
it('displays the time format for a 12-hour clock with seconds', () => {
const opts = { seconds: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm:ss a')
});
it('displays the time format for a 12-hour clock with seconds and timezone', () => {
const opts = { seconds: true, timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm:ss a z')
});
it('displays the time format for a 12-hour clock in uppercase', () => {
const opts = { upperCase: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm A')
});
it('displays the time format for a 12-hour clock in uppercase with seconds', () => {
const opts = { upperCase: true, seconds: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm:ss A')
});
it('displays the time format for a 12-hour clock in uppercase with timezone', () => {
const opts = { upperCase: true, timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm A z')
});
it('displays the time format for a 12-hour clock in uppercase with seconds and timezone', () => {
const opts = { upperCase: true, seconds: true, timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('h:mm:ss A z')
});
});
describe('getTimeFormat: 24-hour clock', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(true)
});
it('displays the time format for a 24-hour clock', () => {
const time = DateUtils.getTimeFormat(null)
expect(time).toBe('HH:mm')
});
it('displays the time format for a 24-hour clock with timezone', () => {
const opts = { timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('HH:mm z')
});
it('displays the time format for a 24-hour clock with seconds', () => {
const opts = { seconds: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('HH:mm:ss')
});
it('displays the time format for a 24-hour clock with seconds and timezone', () => {
const opts = { seconds: true, timeZone: true }
const time = DateUtils.getTimeFormat(opts)
expect(time).toBe('HH:mm:ss z')
});
});
describe('mediumTimeString: 12-hour time', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(false)
});
it('displays a date and time', () => {
const datestring = DateUtils.mediumTimeString('1982-10-24 22:45')
expect(datestring).toBe('October 24, 1982, 10:45 PM')
});
});
describe('mediumTimeString: 24-hour time', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(true)
});
it('displays a date and time', () => {
const datestring = DateUtils.mediumTimeString('1982-10-24 22:45')
expect(datestring).toBe('October 24, 1982, 22:45')
});
});
describe('fullTimeString: 12-hour time', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(false)
self.tz = moment.tz(moment.tz.guess()).zoneAbbr()
});
it('displays a date and time', () => {
const datestring = DateUtils.fullTimeString('1982-10-24 22:45')
expect(datestring).toBe(`Sunday, October 24th 1982, 10:45:00 PM ${self.tz}`)
});
});
describe('fullTimeString: 24-hour time', () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andReturn(true)
self.tz = moment.tz(moment.tz.guess()).zoneAbbr()
});
it('displays a date and time', () => {
const datestring = DateUtils.fullTimeString('1982-10-24 22:45')
expect(datestring).toBe(`Sunday, October 24th 1982, 22:45:00 ${self.tz}`)
});
});
});