diff --git a/.eslintignore b/.eslintignore index 42a8bf0c6..dd420eedb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -109,6 +109,9 @@ packages/app-cli/tests/Synchronizer.tags.js.map packages/app-cli/tests/Synchronizer.tools.d.ts packages/app-cli/tests/Synchronizer.tools.js packages/app-cli/tests/Synchronizer.tools.js.map +packages/app-cli/tests/dateTimeFormats.d.ts +packages/app-cli/tests/dateTimeFormats.js +packages/app-cli/tests/dateTimeFormats.js.map packages/app-cli/tests/fsDriver.d.ts packages/app-cli/tests/fsDriver.js packages/app-cli/tests/fsDriver.js.map diff --git a/.gitignore b/.gitignore index 0d82a7088..91097e049 100644 --- a/.gitignore +++ b/.gitignore @@ -96,6 +96,9 @@ packages/app-cli/tests/Synchronizer.tags.js.map packages/app-cli/tests/Synchronizer.tools.d.ts packages/app-cli/tests/Synchronizer.tools.js packages/app-cli/tests/Synchronizer.tools.js.map +packages/app-cli/tests/dateTimeFormats.d.ts +packages/app-cli/tests/dateTimeFormats.js +packages/app-cli/tests/dateTimeFormats.js.map packages/app-cli/tests/fsDriver.d.ts packages/app-cli/tests/fsDriver.js packages/app-cli/tests/fsDriver.js.map diff --git a/packages/app-cli/tests/dateTimeFormats.ts b/packages/app-cli/tests/dateTimeFormats.ts new file mode 100644 index 000000000..fbd00058e --- /dev/null +++ b/packages/app-cli/tests/dateTimeFormats.ts @@ -0,0 +1,46 @@ +import Setting from '@joplin/lib/models/Setting'; +import time from '@joplin/lib/time'; + +describe('dateFormats', function() { + + beforeEach(async (done) => { + done(); + }); + + it('should format date according to DATE_FORMAT', (async () => { + + const now = new Date('2017-01-30T12:00:00').getTime(); + + // DATE_FORMAT_1 = 'DD/MM/YYYY'; + // DATE_FORMAT_2 = 'DD/MM/YY'; + // DATE_FORMAT_3 = 'MM/DD/YYYY'; + // DATE_FORMAT_4 = 'MM/DD/YY'; + // DATE_FORMAT_5 = 'YYYY-MM-DD'; + // DATE_FORMAT_6 = 'DD.MM.YYYY'; + // DATE_FORMAT_7 = 'YYYY.MM.DD'; + // DATE_FORMAT_8 = 'YYMMDD'; + + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_1)).toBe('30/01/2017'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_2)).toBe('30/01/17'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_3)).toBe('01/30/2017'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_4)).toBe('01/30/17'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_5)).toBe('2017-01-30'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_6)).toBe('30.01.2017'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_7)).toBe('2017.01.30'); + expect(time.formatMsToLocal(now, Setting.DATE_FORMAT_8)).toBe('170130'); + + })); + + it('should format time according to TIME_FORMAT', (async () => { + + const now = new Date('2017-01-30T20:30:00').getTime(); + + // TIME_FORMAT_1 = 'HH:mm'; + // TIME_FORMAT_2 = 'h:mm A'; + + expect(time.formatMsToLocal(now, Setting.TIME_FORMAT_1)).toBe('20:30'); + expect(time.formatMsToLocal(now, Setting.TIME_FORMAT_2)).toBe('8:30 PM'); + + })); + +}); diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 1b8ad30ba..347277a6d 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -131,6 +131,7 @@ class Setting extends BaseModel { public static DATE_FORMAT_5 = 'YYYY-MM-DD'; public static DATE_FORMAT_6 = 'DD.MM.YYYY'; public static DATE_FORMAT_7 = 'YYYY.MM.DD'; + public static DATE_FORMAT_8 = 'YYMMDD'; public static TIME_FORMAT_1 = 'HH:mm'; public static TIME_FORMAT_2 = 'h:mm A'; @@ -562,6 +563,7 @@ class Setting extends BaseModel { options[Setting.DATE_FORMAT_5] = time.formatMsToLocal(now, Setting.DATE_FORMAT_5); options[Setting.DATE_FORMAT_6] = time.formatMsToLocal(now, Setting.DATE_FORMAT_6); options[Setting.DATE_FORMAT_7] = time.formatMsToLocal(now, Setting.DATE_FORMAT_7); + options[Setting.DATE_FORMAT_8] = time.formatMsToLocal(now, Setting.DATE_FORMAT_8); return options; }, storage: SettingStorage.File, diff --git a/readme/terminal.md b/readme/terminal.md index 499bbdfb0..5e1d41e6c 100644 --- a/readme/terminal.md +++ b/readme/terminal.md @@ -378,7 +378,8 @@ The following commands are available in [command-line mode](#command-line-mode): DD/MM/YY (30/01/17), MM/DD/YYYY (01/30/2017), MM/DD/YY (01/30/17), YYYY-MM-DD (2017-01-30), DD.MM.YYYY - (30.01.2017), YYYY.MM.DD (2017.01.30). + (30.01.2017), YYYY.MM.DD (2017.01.30), + YYMMDD (170130). Default: "DD/MM/YYYY" timeFormat Time format.