human-interval
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "human-interval", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"repo": "rschmukler/human-interval", | ||
@@ -5,0 +5,0 @@ "description": "Human readable time measurements", |
0.1.2 / 2014-01-03 | ||
================== | ||
* Added support for 'week' unit | ||
0.1.1 / 2013-10-28 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,3 +5,3 @@ var humanInterval = module.exports = function humanInterval(time) { | ||
time = swapLanguageToDecimals(time); | ||
time = time.replace(/(second|minute|hour|day|year)s?(?! ?(s )?and |s?$)/, '\$1,'); | ||
time = time.replace(/(second|minute|hour|day|week|year)s?(?! ?(s )?and |s?$)/, '$1,'); | ||
return time.split(/and|,/).reduce(function(sum, group) { | ||
@@ -26,5 +26,5 @@ return sum + processUnits(group); | ||
function swapLanguageToDecimals(time) { | ||
language = humanInterval.languageMap; | ||
var language = humanInterval.languageMap; | ||
var languageMapRegex = new RegExp('(' + Object.keys(language).join('|') + ')', 'g'); | ||
var matches = time.match(languageMapRegex) | ||
var matches = time.match(languageMapRegex); | ||
if(!matches) return time; | ||
@@ -42,3 +42,3 @@ | ||
var num = parseFloat(time, 10), | ||
unit = time.match(/(second|minute|hour|day|year)s?/)[1]; | ||
unit = time.match(/(second|minute|hour|day|week|year)s?/)[1]; | ||
@@ -50,2 +50,3 @@ switch(unit) { | ||
case 'day': unit = 1000 * 60 * 60 * 24; break; | ||
case 'week': unit = 1000 * 60 * 60 * 24 * 7; break; | ||
case 'year': unit = 1000 * 60 * 60 * 24 * 365; break; | ||
@@ -52,0 +53,0 @@ } |
{ | ||
"name": "human-interval", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Human readable time measurements", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,2 +26,5 @@ var expect = require('expect.js'), | ||
}); | ||
it('understands weeks', function() { | ||
expect(humanInterval('1 week')).to.be(7 * 86400000); | ||
}); | ||
it('understands years', function() { | ||
@@ -28,0 +31,0 @@ expect(humanInterval('1 year')).to.be(31536000000); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5634
112