Skip to content

Commit

Permalink
All: Add new date format YYMMDD (#4954)
Browse files Browse the repository at this point in the history
  • Loading branch information
tessus authored May 13, 2021
1 parent ce80d7e commit fa6981f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions packages/app-cli/tests/dateTimeFormats.ts
Original file line number Diff line number Diff line change
@@ -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');

}));

});
2 changes: 2 additions & 0 deletions packages/lib/models/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion readme/terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fa6981f

Please sign in to comment.