Added license

This commit is contained in:
Henry
2016-07-25 12:09:15 -04:00
parent 19fd63b850
commit a4f6f6f50b
3 changed files with 47 additions and 45 deletions

View File

@ -61,6 +61,17 @@ define([
"key": "DEFAULT_TIME_FORMAT",
"value": "utc"
}
],
"licenses": [
{
"name": "d3",
"version": "3.0.0",
"description": "Incorporates modified code from d3 Time Scales",
"author": "Mike Bostock",
"copyright": "Copyright 2010-2016 Mike Bostock. " +
"All rights reserved.",
"link": "https://github.com/d3/d3/blob/master/LICENSE"
}
]
}
});

View File

@ -41,6 +41,12 @@ define([
DAYS = 24 * HOURS,
MONTHS = (365 / 12) * DAYS;
/**
* @typedef Scale
* @property {number} min the minimum scale value, in ms
* @property {number} max the maximum scale value, in ms
*/
/**
* Formatter for UTC timestamps. Interprets numeric values as
* milliseconds since the start of 1970.
@ -57,42 +63,43 @@ define([
* the threshold required.
* @private
*/
function getScaledFormat (d, threshold) {
//Adapted from D3 formatting rules
if (!(d instanceof Date)){
d = new Date(moment.utc(d));
}
function getScaledFormat (d) {
var m = moment.utc(d);
/**
* Uses logic from d3 Time-Scales, v3 of the API. See
* https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md
*
* Licensed
*/
return [
[".SSS", function(d) { return d.getMilliseconds() >= threshold; }],
[":ss", function(d) { return d.getSeconds() * SECONDS >= threshold; }],
["HH:mm", function(d) { return d.getMinutes() * MINUTES >= threshold; }],
["HH", function(d) { return d.getHours() * HOURS >= threshold; }],
["ddd DD", function(d) {
return d.getDay() * DAYS >= threshold &&
d.getDate() != 1;
[".SSS", function(m) { return m.milliseconds(); }],
[":ss", function(m) { return m.seconds(); }],
["HH:mm", function(m) { return m.minutes(); }],
["HH", function(m) { return m.hours(); }],
["ddd DD", function(m) {
return m.days() &&
m.date() != 1;
}],
["MMM DD", function(d) { return d.getDate() != 1; }],
["MMMM", function(d) {
return d.getMonth() * MONTHS >= threshold;
["MMM DD", function(m) { return m.date() != 1; }],
["MMMM", function(m) {
return m.month();
}],
["YYYY", function() { return true; }]
].filter(function (row){
return row[1](d);
return row[1](m);
})[0][0];
};
/**
*
* @param value
* @param {number} [threshold] Optionally provides context to the
* format request, allowing for scale-appropriate formatting. This value
* should be the minimum unit to be represented by this format, in ms. For
* example, to display seconds, a threshold of 1 * 1000 should be provided.
* @param {Scale} [scale] Optionally provides context to the
* format request, allowing for scale-appropriate formatting.
* @returns {string} the formatted date
*/
UTCTimeFormat.prototype.format = function (value, threshold) {
if (threshold !== undefined){
var scaledFormat = getScaledFormat(value, threshold);
UTCTimeFormat.prototype.format = function (value, scale) {
if (scale !== undefined){
var scaledFormat = getScaledFormat(value, scale);
if (scaledFormat) {
return moment.utc(value).format(scaledFormat);
}