pax_global_header00006660000000000000000000000064131252377120014515gustar00rootroot0000000000000052 comment=a4d5e8c83fe1bac18c3ec373228c7155b00f99aa date-time-2.1.0/000077500000000000000000000000001312523771200133665ustar00rootroot00000000000000date-time-2.1.0/.editorconfig000066400000000000000000000002571312523771200160470ustar00rootroot00000000000000root = 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-2.1.0/.gitattributes000066400000000000000000000000351312523771200162570ustar00rootroot00000000000000* text=auto *.js text eol=lf date-time-2.1.0/.gitignore000066400000000000000000000000151312523771200153520ustar00rootroot00000000000000node_modules date-time-2.1.0/.travis.yml000066400000000000000000000000531312523771200154750ustar00rootroot00000000000000language: node_js node_js: - '6' - '4' date-time-2.1.0/index.js000066400000000000000000000013231312523771200150320ustar00rootroot00000000000000'use strict'; const timeZone = require('time-zone'); module.exports = options => { options = Object.assign({ date: new Date(), local: true, showTimeZone: false, showMilliseconds: false }, options); let date = options.date; 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); }; date-time-2.1.0/license000066400000000000000000000021371312523771200147360ustar00rootroot00000000000000The MIT License (MIT) 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-2.1.0/package.json000066400000000000000000000012161312523771200156540ustar00rootroot00000000000000{ "name": "date-time", "version": "2.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": ">=4" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "datetime", "date-time", "date", "time", "utc", "iso", "timezone", "zone", "timestamp" ], "dependencies": { "time-zone": "^1.0.0" }, "devDependencies": { "ava": "*", "xo": "*" } } date-time-2.1.0/readme.md000066400000000000000000000021731312523771200151500ustar00rootroot00000000000000# 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 --save 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-2.1.0/test.js000066400000000000000000000011071312523771200147020ustar00rootroot00000000000000import test from 'ava'; import m from '.'; test('main', t => { t.regex(m(), /^[\d-]+ [\d:]+$/); t.regex(m({date: new Date()}), /^[\d-]+ [\d:]+$/); }); test('showTimeZone option', t => { t.regex(m({showTimeZone: true}), /^[\d-]+ [\d:]+ UTC[-+][\d:]+$/); t.regex(m({ local: false, showTimeZone: true }), /^[\d-]+ [\d:]+ UTC$/); }); test('showMilliseconds option', t => { t.regex(m({ local: false, showMilliseconds: true }), /^[\d-]+ [\d:]+ \d+ms$/); t.regex(m({ local: false, showMilliseconds: true, showTimeZone: true }), /^[\d-]+ [\d:]+ \d+ms UTC$/); });