[Time Conductor] Remove non-format-like methods

...from UTCTimeSystem, and rename to UTCTimeFormat. Per code
review feedback from nasa/openmctweb#182.
This commit is contained in:
Victor Woeltjen 2015-10-26 09:45:01 -07:00
parent 111b3bac09
commit c45bf45475
2 changed files with 12 additions and 35 deletions

View File

@ -14,6 +14,12 @@
"implementation": "UTCTimeProvider.js",
"depends": [ "now" ]
}
],
"formats": [
{
"key": "utc",
"implementation": "UTCTimeFormat.js"
}
]
}
}

View File

@ -34,52 +34,23 @@ define([
"YYYY-MM-DD HH:mm:ss",
"YYYY-MM-DD HH:mm",
"YYYY-MM-DD"
],
SECOND = 1000,
MINUTE = 60 * SECOND,
HOUR = 60 * MINUTE,
DAY = 24 * HOUR,
WEEK = 7 * DAY,
MONTH_APPROX = 30 * DAY,
YEAR = 365 * DAY,
INCREMENTS = [
SECOND,
MINUTE,
HOUR,
DAY,
WEEK,
MONTH_APPROX,
YEAR
],
DEFAULT_INCREMENT = 3;
];
function UTCTimeSystem(now) {
this.nowFn = now;
function UTCTimeFormat() {
}
UTCTimeSystem.prototype.format = function (value) {
UTCTimeFormat.prototype.format = function (value) {
return moment.utc(value).format(DATE_FORMAT);
};
UTCTimeSystem.prototype.parse = function (text) {
UTCTimeFormat.prototype.parse = function (text) {
return moment.utc(text, DATE_FORMATS).valueOf();
};
UTCTimeSystem.prototype.validate = function (text) {
UTCTimeFormat.prototype.validate = function (text) {
return moment.utc(text, DATE_FORMATS).isValid();
};
UTCTimeSystem.prototype.now = function () {
return this.nowFn();
};
UTCTimeSystem.prototype.increment = function (scale) {
var index = (scale || 0) + DEFAULT_INCREMENT;
index = Math.max(index, 0);
index = Math.min(index, INCREMENTS.length - 1);
return INCREMENTS[index];
};
return UTCTimeSystem;
return UTCTimeFormat;
});