Merge pull request #26478 from whatasoda/moment-shortformat

Added declaration of moment-shortformat
This commit is contained in:
Nathan Shively-Sanders
2018-06-19 15:09:07 -07:00
committed by GitHub
4 changed files with 60 additions and 0 deletions

16
types/moment-shortformat/index.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
// Type definitions for moment-shortformat 2.1
// Project: https://github.com/researchgate/moment-shortformat#readme
// Definitions by: whatasoda <https://github.com/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;
}
}

View File

@@ -0,0 +1,20 @@
import moment = require('moment');
import 'moment-shortformat';
let formatted: string;
/*~ Formats time relative to current time. */
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
*/
formatted = moment(moment().valueOf() + 6048e5).short(); // 'Mar 7'
/*~ Using a different "now" */
formatted = moment(moment().valueOf() + (36e5 * 5)).short(
false, moment(moment().valueOf() + (36e5 * 3))
); // 'in 2h'

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }