date-frequency
Advanced tools
Comparing version 0.2.6 to 0.3.0
@@ -171,2 +171,18 @@ var util = require('./util'), | ||
Frequency.prototype.compare = function (frequency) { | ||
// warning: only compares those units that appear in both frequencies, with both the same scope! | ||
for (var i = 0;i < util.unit.order.length;i++) { | ||
var unit = util.unit.order[i]; | ||
if (this.rules[unit] && frequency.rules[unit] && this.rules[unit].scope === frequency.rules[unit].scope) { | ||
if (this.rules[unit].fix < frequency.rules[unit].fix) { | ||
return -1; | ||
} else if (this.rules[unit].fix > frequency.rules[unit].fix) { | ||
return 1; | ||
} | ||
} | ||
} | ||
return 0; | ||
}; | ||
Frequency.prototype.toString = function () { | ||
@@ -173,0 +189,0 @@ var str = 'F', |
@@ -5,4 +5,3 @@ var rest = require('lodash.rest'), | ||
var order = ['Y', 'M', 'D', 'h', 'm', 's'], | ||
names = { | ||
var names = { | ||
'year': 'Y', | ||
@@ -18,2 +17,3 @@ 'month': 'M', | ||
var util = { | ||
order: ['Y', 'M', 'D', 'h', 'm', 's'], | ||
defaults: { | ||
@@ -38,3 +38,3 @@ 'M': 1, | ||
if (indexof(order.concat(['W']), unit) < 0) { | ||
if (indexof(util.order.concat(['W']), unit) < 0) { | ||
return undefined; | ||
@@ -51,6 +51,6 @@ } | ||
lower: function (unit) { | ||
return rest(order, indexof(order, unit) + 1); | ||
return rest(util.order, indexof(util.order, unit) + 1); | ||
}, | ||
higher: function (unit) { | ||
return first(order, indexof(order, unit)); | ||
return first(util.order, indexof(util.order, unit)); | ||
}, | ||
@@ -57,0 +57,0 @@ between: function (left, right) { |
{ | ||
"name": "date-frequency", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "Temporal frequency library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
13820
350