diff --git a/types/jquery-formatdatetime/index.d.ts b/types/jquery-formatdatetime/index.d.ts new file mode 100644 index 0000000000..308d58fe7f --- /dev/null +++ b/types/jquery-formatdatetime/index.d.ts @@ -0,0 +1,64 @@ +// Type definitions for JQuery formatDateTime 1.1 +// Project: https://github.com/agschwender/jquery.formatDateTime +// Definitions by: Anderson Friaça +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +export type Options = Partial<{ + /** + * Names of the months, e.g. January + */ + monthNames: string[]; + + /** + * Shortened names of the months, e.g. Jan + */ + monthNamesShort: string[]; + + /** + * Names of the days, e.g. Sunday + */ + dayNames: string[]; + + /** + * Shortened names of the days, e.g. Sun + */ + dayNamesShort: string[]; + + /** + * Names of the 12-hour clock periods, e.g. AM + */ + ampmNames: string[]; + + /** + * Callback to convert number to ordinal suffix, e.g. 1 to st + */ + getSuffix: ((num: number) => string); + + /** + * Attribute which contains the datetime + */ + attribute: string; + + /** + * Attribute which contains the datetime format + */ + formatAttribute: string; + + /** + * Render dates in UTC instead of local timezone + */ + utc: boolean; +}>; + +declare global { + interface JQuery { + formatDateTime(format: string, options?: Options): JQuery; + } + + interface JQueryStatic { + formatDateTime(format: string, date: Date, options?: Options): string; + } +} diff --git a/types/jquery-formatdatetime/jquery-formatdatetime-tests.ts b/types/jquery-formatdatetime/jquery-formatdatetime-tests.ts new file mode 100644 index 0000000000..fe5949f757 --- /dev/null +++ b/types/jquery-formatdatetime/jquery-formatdatetime-tests.ts @@ -0,0 +1,40 @@ +import { Options } from "jquery-formatdatetime"; + +// basic usage +$('#example').formatDateTime('mm/dd/y g:ii a'); + +const date = new Date('2012/07/05 09:55:03'); + +$.formatDateTime('mm/dd/y g:ii a', date); + +// with options +const options: Options = { + monthNames: [ + 'Janeiro', + 'Fevereiro', + 'Março', + 'Abril', + 'Maio', + 'Junho', + 'Julho', + 'Agosto', + 'Setembro', + 'Outubro', + 'Novembro', + 'Dezembro' + ], + dayNames: [ + 'Domingo', + 'Segunda-Feira', + 'Terça-Feira', + 'Quarta-Feira', + 'Quinta-Feira', + 'Sexta-Feira', + 'Sábado' + ], + ampmNames: ['AM', 'PM'] +}; + +$.formatDateTime('mm/dd/y g:ii a', date, options); + +$('#example').formatDateTime('mm/dd/y g:ii a', options); diff --git a/types/jquery-formatdatetime/tsconfig.json b/types/jquery-formatdatetime/tsconfig.json new file mode 100644 index 0000000000..a6ba781d22 --- /dev/null +++ b/types/jquery-formatdatetime/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jquery-formatdatetime-tests.ts" + ] +} \ No newline at end of file diff --git a/types/jquery-formatdatetime/tslint.json b/types/jquery-formatdatetime/tslint.json new file mode 100644 index 0000000000..d04fe2e1fa --- /dev/null +++ b/types/jquery-formatdatetime/tslint.json @@ -0,0 +1 @@ +{"extends": "dtslint/dt.json"} \ No newline at end of file