pax_global_header00006660000000000000000000000064134505444410014516gustar00rootroot0000000000000052 comment=63431bde09f030fdef007e645f707c4b3de2650a date-time-3.1.0/000077500000000000000000000000001345054444100133705ustar00rootroot00000000000000date-time-3.1.0/.editorconfig000066400000000000000000000002571345054444100160510ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 date-time-3.1.0/.gitattributes000066400000000000000000000000231345054444100162560ustar00rootroot00000000000000* text=auto eol=lf date-time-3.1.0/.gitignore000066400000000000000000000000271345054444100153570ustar00rootroot00000000000000node_modules yarn.lock date-time-3.1.0/.npmrc000066400000000000000000000000231345054444100145030ustar00rootroot00000000000000package-lock=false date-time-3.1.0/.travis.yml000066400000000000000000000000641345054444100155010ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' - '6' date-time-3.1.0/index.d.ts000066400000000000000000000022531345054444100152730ustar00rootroot00000000000000declare namespace dateTime { interface Options { /** Custom date. @default new Date() */ date?: Date; /** Show the date in the local time zone. @default false */ local?: boolean; /** Show the UTC time zone postfix. @default false */ showTimeZone?: boolean; /** Show the milliseconds in the date if any. @default false */ showMilliseconds?: boolean; } } declare const dateTime: { /** Pretty datetime: `2014-01-09 06:46:01`. @example ``` import dateTime = require('date-time'); dateTime(); //=> '2017-05-20 17:07:05' dateTime({date: new Date(1989, 2, 4, 10)}); //=> '1989-03-04 09:00:00' dateTime({showTimeZone: true}); //=> '2017-05-20 17:07:05 UTC+7' dateTime({local: false}); //=> '2017-05-20 10:07:05' dateTime({local: false, showTimeZone: true}); //=> '2017-05-20 10:07:05 UTC' dateTime({showMilliseconds: true}); //=> '2017-05-20 17:07:05 6ms' ``` */ (options?: dateTime.Options): string; // TODO: Remove this for the next major release, refactor the whole definition to: // declare function dateTime(options?: dateTime.Options): string; // export = dateTime; default: typeof dateTime; }; export = dateTime; date-time-3.1.0/index.js000066400000000000000000000014771345054444100150460ustar00rootroot00000000000000'use strict'; const timeZone = require('time-zone'); const dateTime = options => { options = Object.assign({ date: new Date(), local: true, showTimeZone: false, showMilliseconds: false }, options); let {date} = options; if (options.local) { // Offset the date so it will return the correct value when getting the ISO string date = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)); } let end = ''; if (options.showTimeZone) { end = ' UTC' + (options.local ? timeZone(date) : ''); } if (options.showMilliseconds && date.getUTCMilliseconds() > 0) { end = ` ${date.getUTCMilliseconds()}ms${end}`; } return date .toISOString() .replace(/T/, ' ') .replace(/\..+/, end); }; module.exports = dateTime; // TODO: Remove this for the next major release module.exports.default = dateTime; date-time-3.1.0/index.test-d.ts000066400000000000000000000005751345054444100162550ustar00rootroot00000000000000import {expectType} from 'tsd'; import dateTime = require('.'); expectType(dateTime()); expectType(dateTime({date: new Date(1989, 2, 4, 10)})); expectType(dateTime({showTimeZone: true})); expectType(dateTime({local: false})); expectType(dateTime({local: false, showTimeZone: true})); expectType(dateTime({showMilliseconds: true})); date-time-3.1.0/license000066400000000000000000000021251345054444100147350ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. date-time-3.1.0/package.json000066400000000000000000000012141345054444100156540ustar00rootroot00000000000000{ "name": "date-time", "version": "3.1.0", "description": "Pretty datetime: `2014-01-09 06:46:01`", "license": "MIT", "repository": "sindresorhus/date-time", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=6" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "datetime", "date-time", "date", "time", "utc", "iso", "timezone", "zone", "timestamp" ], "dependencies": { "time-zone": "^1.0.0" }, "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.1", "xo": "^0.24.0" } } date-time-3.1.0/readme.md000066400000000000000000000021641345054444100151520ustar00rootroot00000000000000# date-time [![Build Status](https://travis-ci.org/sindresorhus/date-time.svg?branch=master)](https://travis-ci.org/sindresorhus/date-time) > Pretty datetime: `2014-01-09 06:46:01` ## Install ``` $ npm install date-time ``` ## Usage ```js const dateTime = require('date-time'); dateTime(); //=> '2017-05-20 17:07:05' dateTime({date: new Date(1989, 2, 4, 10)}); //=> '1989-03-04 09:00:00' dateTime({showTimeZone: true}); //=> '2017-05-20 17:07:05 UTC+7' dateTime({local: false}); //=> '2017-05-20 10:07:05' dateTime({local: false, showTimeZone: true}); //=> '2017-05-20 10:07:05 UTC' dateTime({showMilliseconds: true}); //=> '2017-05-20 17:07:05 6ms' ``` ## API ### dateTime([options]) ### options Type: `Object` #### date Type: `Date`
Default: `new Date()` Custom date. #### local Type: `boolean`
Default: `true` Show the date in the local time zone. #### showTimeZone Type: `boolean`
Default: `false` Show the UTC time zone postfix. #### showMilliseconds Type: `boolean`
Default: `false` Show the milliseconds in the date if any. ## License MIT © [Sindre Sorhus](https://sindresorhus.com) date-time-3.1.0/test.js000066400000000000000000000011701345054444100147040ustar00rootroot00000000000000import test from 'ava'; import dateTime from '.'; test('main', t => { t.regex(dateTime(), /^[\d-]+ [\d:]+$/); t.regex(dateTime({date: new Date()}), /^[\d-]+ [\d:]+$/); }); test('showTimeZone option', t => { t.regex(dateTime({showTimeZone: true}), /^[\d-]+ [\d:]+ UTC[-+][\d:]+$/); t.regex(dateTime({ local: false, showTimeZone: true }), /^[\d-]+ [\d:]+ UTC$/); }); test('showMilliseconds option', t => { t.regex(dateTime({ local: false, showMilliseconds: true }), /^[\d-]+ [\d:]+ \d+ms$/); t.regex(dateTime({ local: false, showMilliseconds: true, showTimeZone: true }), /^[\d-]+ [\d:]+ \d+ms UTC$/); });