From 1d2f4b6585b051ebe25d373baf0544dfe3dc8ea7 Mon Sep 17 00:00:00 2001 From: whatasoda Date: Tue, 12 Jun 2018 18:40:53 +0900 Subject: [PATCH 1/2] Added declaration of moment-shortformat --- types/moment-shortformat/index.d.ts | 16 +++++++++++++ .../moment-shortformat-tests.ts | 20 ++++++++++++++++ types/moment-shortformat/tsconfig.json | 23 +++++++++++++++++++ types/moment-shortformat/tslint.json | 1 + 4 files changed, 60 insertions(+) create mode 100644 types/moment-shortformat/index.d.ts create mode 100644 types/moment-shortformat/moment-shortformat-tests.ts create mode 100644 types/moment-shortformat/tsconfig.json create mode 100644 types/moment-shortformat/tslint.json diff --git a/types/moment-shortformat/index.d.ts b/types/moment-shortformat/index.d.ts new file mode 100644 index 0000000000..d5125aac49 --- /dev/null +++ b/types/moment-shortformat/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for moment-shortformat 2.1 +// Project: https://github.com/researchgate/moment-shortformat#readme +// Definitions by: whatasoda +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace moment; + +import moment = require('moment'); + +export = moment; + +declare module 'moment' { + interface Moment { + short(withoutPreOrSuffix?: boolean, now?: Moment): string; + } +} diff --git a/types/moment-shortformat/moment-shortformat-tests.ts b/types/moment-shortformat/moment-shortformat-tests.ts new file mode 100644 index 0000000000..a0050348f7 --- /dev/null +++ b/types/moment-shortformat/moment-shortformat-tests.ts @@ -0,0 +1,20 @@ +import moment = require('moment'); +import momentShortformat = require('moment-shortformat'); + +moment === momentShortformat; // true + +/*~ Formats time relative to current time. */ +moment(moment().valueOf() + (36e5 * 5)).short(); // in 5h +moment(moment().valueOf() - (36e5 * 5)).short(); // 5h ago +moment(moment().valueOf() + (36e5 * 5)).short(true); // 5h +moment(moment().valueOf() - (36e5 * 5)).short(true); // 5h + +/*~ Times greater than 1 week are converted to dates like Mar 7, + *~ or if the year of the date does not match the current year + *~ it is convert to Mar 7, 2031 + */ +moment(moment().valueOf() + 6048e5).short(); // Mar 7 + +/*~ Using a different "now" */ +moment(moment().valueOf() + (36e5 * 5)) + .short(false, moment(moment().valueOf() + (36e5 * 3))); // in 2h diff --git a/types/moment-shortformat/tsconfig.json b/types/moment-shortformat/tsconfig.json new file mode 100644 index 0000000000..96fd6c6524 --- /dev/null +++ b/types/moment-shortformat/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "moment-shortformat-tests.ts" + ] +} diff --git a/types/moment-shortformat/tslint.json b/types/moment-shortformat/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/moment-shortformat/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 9fc95b02e18310ed7df8b41da5c6013988f0d0e7 Mon Sep 17 00:00:00 2001 From: whatasoda Date: Wed, 13 Jun 2018 00:27:31 +0900 Subject: [PATCH 2/2] Modified test --- .../moment-shortformat-tests.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/moment-shortformat/moment-shortformat-tests.ts b/types/moment-shortformat/moment-shortformat-tests.ts index a0050348f7..84f754a750 100644 --- a/types/moment-shortformat/moment-shortformat-tests.ts +++ b/types/moment-shortformat/moment-shortformat-tests.ts @@ -1,20 +1,20 @@ import moment = require('moment'); -import momentShortformat = require('moment-shortformat'); - -moment === momentShortformat; // true +import 'moment-shortformat'; +let formatted: string; /*~ Formats time relative to current time. */ -moment(moment().valueOf() + (36e5 * 5)).short(); // in 5h -moment(moment().valueOf() - (36e5 * 5)).short(); // 5h ago -moment(moment().valueOf() + (36e5 * 5)).short(true); // 5h -moment(moment().valueOf() - (36e5 * 5)).short(true); // 5h +formatted = moment(moment().valueOf() + (36e5 * 5)).short(); // 'in 5h' +formatted = moment(moment().valueOf() - (36e5 * 5)).short(); // '5h ago' +formatted = moment(moment().valueOf() + (36e5 * 5)).short(true); // '5h' +formatted = moment(moment().valueOf() - (36e5 * 5)).short(true); // '5h' /*~ Times greater than 1 week are converted to dates like Mar 7, *~ or if the year of the date does not match the current year *~ it is convert to Mar 7, 2031 */ -moment(moment().valueOf() + 6048e5).short(); // Mar 7 +formatted = moment(moment().valueOf() + 6048e5).short(); // 'Mar 7' /*~ Using a different "now" */ -moment(moment().valueOf() + (36e5 * 5)) - .short(false, moment(moment().valueOf() + (36e5 * 3))); // in 2h +formatted = moment(moment().valueOf() + (36e5 * 5)).short( + false, moment(moment().valueOf() + (36e5 * 3)) +); // 'in 2h'