-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b8ae3fa
Showing
11 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false | ||
|
||
[test/**/*] | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Enforce Unix newlines | ||
* text eol=lf | ||
|
||
# binaries | ||
*.ai binary | ||
*.psd binary | ||
*.jpg binary | ||
*.gif binary | ||
*.png binary | ||
*.jpeg binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.DS_Store | ||
*.sublime-* | ||
_gh_pages | ||
bower_components | ||
node_modules | ||
npm-debug.log | ||
actual | ||
test/actual | ||
temp | ||
tmp | ||
TODO.md | ||
vendor | ||
.idea | ||
benchmark | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"asi": false, | ||
"boss": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"esnext": true, | ||
"immed": true, | ||
"latedef": false, | ||
"laxcomma": false, | ||
"mocha": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
- "iojs" | ||
git: | ||
depth: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# {%= name %} {%= badge("fury") %} | ||
|
||
> {%= description %} | ||
{%= include("install-npm", {save: true}) %} | ||
|
||
## Usage | ||
|
||
```js | ||
var timestamp = require('{%= name %}'); | ||
|
||
timestamp('YYYY:MM:DD'); | ||
//=> '2015:04:01' | ||
|
||
timestamp('[YYYY:MM:DD]'); | ||
//=> '[2015:04:01]' | ||
|
||
timestamp('YYYY/MM/DD'); | ||
//=> '2015/04/01' | ||
|
||
timestamp('YYYY'); | ||
//=> '2015' | ||
|
||
timestamp('MM'); | ||
//=> '04' | ||
|
||
timestamp('DD'); | ||
//=> '01' | ||
|
||
timestamp('mm'); | ||
//=> '59' | ||
|
||
timestamp('ss'); | ||
//=> '09' | ||
|
||
timestamp('ms'); | ||
//=> '783' | ||
``` | ||
|
||
**Valid patterns** | ||
|
||
- `YYYY`: full year (ex: **2015**) | ||
- `MM`: month (ex: **04**) | ||
- `DD`: day (ex: **01**) | ||
- `HH`: hours (ex: **12**) | ||
- `mm`: minutes (ex: **59**) | ||
- `ss`: seconds (ex: **09**) | ||
- `ms`: milliseconds (ex: **532**) | ||
|
||
## Related projects | ||
{%= related(['year', 'month', 'months', 'days', 'seconds', 'weekday', 'week', 'o-clock']) %} | ||
|
||
## Running tests | ||
{%= include("tests") %} | ||
|
||
## Contributing | ||
{%= include("contributing") %} | ||
|
||
## Author | ||
{%= include("author") %} | ||
|
||
## License | ||
{%= copyright() %} | ||
{%= license() %} | ||
|
||
*** | ||
|
||
{%= include("footer") %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015, Jon Schlinkert. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# time-stamp [![NPM version](https://badge.fury.io/js/time-stamp.svg)](http://badge.fury.io/js/time-stamp) | ||
|
||
> Get a formatted timestamp. | ||
## Install with [npm](npmjs.org) | ||
|
||
```bash | ||
npm i time-stamp --save | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
var timestamp = require('time-stamp'); | ||
|
||
timestamp('YYYY:MM:DD'); | ||
//=> '2015:04:01' | ||
|
||
timestamp('[YYYY:MM:DD]'); | ||
//=> '[2015:04:01]' | ||
|
||
timestamp('YYYY/MM/DD'); | ||
//=> '2015/04/01' | ||
|
||
timestamp('YYYY'); | ||
//=> '2015' | ||
|
||
timestamp('MM'); | ||
//=> '04' | ||
|
||
timestamp('DD'); | ||
//=> '01' | ||
|
||
timestamp('mm'); | ||
//=> '59' | ||
|
||
timestamp('ss'); | ||
//=> '09' | ||
|
||
timestamp('ms'); | ||
//=> '783' | ||
``` | ||
|
||
**Valid patterns** | ||
|
||
* `YYYY`: full year (ex: **2015**) | ||
* `MM`: month (ex: **04**) | ||
* `DD`: day (ex: **01**) | ||
* `HH`: hours (ex: **12**) | ||
* `mm`: minutes (ex: **59**) | ||
* `ss`: seconds (ex: **09**) | ||
* `ms`: milliseconds (ex: **532**) | ||
|
||
## Related projects | ||
|
||
* [days](https://github.com/jonschlinkert/days): Days of the week. | ||
* [month](https://github.com/jonschlinkert/month): Get the name or number of the current month or any month of the year. | ||
* [months](https://github.com/jonschlinkert/months): Months of the year. | ||
* [o-clock](https://github.com/jonschlinkert/o-clock): Simple utility for displaying the time in 12-hour clock format. | ||
* [seconds](https://github.com/jonschlinkert/seconds): Get the number of seconds for a minute, hour, day and week. | ||
* [weekday](https://github.com/jonschlinkert/weekday): Get the name and number of the current weekday. Or get the name of the… [more](https://github.com/jonschlinkert/weekday) | ||
* [week](https://github.com/jonschlinkert/week): Get the current week number. | ||
* [year](https://github.com/jonschlinkert/year): Simple utility to get the current year with 2 or 4 digits. | ||
|
||
## Running tests | ||
|
||
Install dev dependencies: | ||
|
||
```bash | ||
npm i -d && npm test | ||
``` | ||
|
||
## Contributing | ||
|
||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/time-stamp/issues) | ||
|
||
## Author | ||
|
||
**Jon Schlinkert** | ||
|
||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
|
||
## License | ||
|
||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
|
||
*** | ||
|
||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 01, 2015._ | ||
|
||
<!-- reflinks generated by verb-reflinks plugin --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*! | ||
* time-stamp <https://github.com/jonschlinkert/time-stamp> | ||
* | ||
* Copyright (c) 2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var pad = require('pad-left'); | ||
|
||
/** | ||
* Expose `timestamp` | ||
*/ | ||
|
||
/** | ||
* Parse the given pattern and return a formatted | ||
* timestamp. | ||
* | ||
* @param {String} `pattern` Date pattern. | ||
* @param {Date} `date` Date object. | ||
* @return {String} | ||
*/ | ||
|
||
module.exports = function timestamp(pattern, date) { | ||
if (typeof pattern !== 'string') { | ||
date = pattern; | ||
pattern = 'YYYY:MM:DD'; | ||
} | ||
date = date || new Date(); | ||
return pattern.replace(/([YMDHms]{2,4})(:\/)?/g, function (_, key, sep) { | ||
var time = method(key); | ||
if (!time) return _; | ||
|
||
var res = date[time]().toString(); | ||
var diff = key.length - res.length; | ||
return pad(res, diff, 0) + (sep || ''); | ||
}); | ||
}; | ||
|
||
function method(key) { | ||
return ({ | ||
YYYY: 'getFullYear', | ||
YY: 'getFullYear', | ||
MM: 'getMonth', | ||
DD: 'getDate', | ||
HH: 'getHours', | ||
mm: 'getMinutes', | ||
ss: 'getSeconds', | ||
ms: 'getMilliseconds' | ||
})[key]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "time-stamp", | ||
"description": "Get a formatted timestamp.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/jonschlinkert/time-stamp", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/time-stamp.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/time-stamp/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/time-stamp/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"pad-left": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"keywords": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/*! | ||
* time-stamp <https://github.com/jonschlinkert/time-stamp> | ||
* | ||
* Copyright (c) 2015 Jon Schlinkert. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/* deps:mocha */ | ||
var assert = require('assert'); | ||
var should = require('should'); | ||
var timestamp = require('./'); | ||
|
||
describe('timestamp', function () { | ||
it('should return the default timestamp:', function () { | ||
timestamp().should.match(/^\d{4}:\d{2}:\d{2}$/); | ||
}); | ||
|
||
it('should return the year:', function () { | ||
timestamp('YYYY').should.match(/^\d{4}$/); | ||
}); | ||
|
||
it('should return the month:', function () { | ||
timestamp('MM').should.match(/^\d{2}$/); | ||
}); | ||
|
||
it('should return the day:', function () { | ||
timestamp('DD').should.match(/^\d{2}$/); | ||
}); | ||
|
||
it('should return hours:', function () { | ||
timestamp('HH').should.match(/^\d{2}$/); | ||
}); | ||
|
||
it('should return minutes:', function () { | ||
timestamp('mm').should.match(/^\d{2}$/); | ||
}); | ||
|
||
it('should return seconds:', function () { | ||
timestamp('ss').should.match(/^\d{2}$/); | ||
}); | ||
|
||
it('should return miliseconds:', function () { | ||
timestamp('ms').should.match(/^\d{3}$$/); | ||
}); | ||
}); |