Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Upgrade d3 time format to expose new formatting options for weekdays, weeks and quarters by archmoj · Pull Request #5026 · plotly/plotly.js · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@
"d3-force": "^1.2.1",
"d3-hierarchy": "^1.1.9",
"d3-interpolate": "^1.4.0",
"d3-time-format": "^2.2.3",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^4.2.8",
"fast-isnumeric": "^1.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/docs.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,5 +10,5 @@

module.exports = {
FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format',
DATE_FORMAT_LINK: 'https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format'
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
};
6 changes: 3 additions & 3 deletions src/lib/dates.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@

'use strict';

var d3 = require('d3');
var timeFormat = require('d3-time-format').timeFormat;
var isNumeric = require('fast-isnumeric');

var Loggers = require('./loggers');
Expand All@@ -25,7 +25,7 @@ var EPOCHJD = constants.EPOCHJD;

var Registry = require('../registry');

var utcFormat = d3.time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d(:?\d\d)?)?)?)?)?)?\s*$/m;
// special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
Expand DownExpand Up@@ -306,7 +306,7 @@ exports.ms2DateTimeLocal = function(ms) {

var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10);
var d = new Date(Math.round(ms - msecTenths / 10));
var dateStr = d3.time.format('%Y-%m-%d')(d);
var dateStr = timeFormat('%Y-%m-%d')(d);
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var numConstants = require('../constants/numerical');
Expand DownExpand Up@@ -1082,7 +1083,7 @@ function templateFormatString(string, labels, d3locale) {
}

if(format[0] === '|') {
fmt = d3locale ? d3locale.timeFormat.utc : d3.time.format.utc;
fmt = d3locale ? d3locale.timeFormat : utcFormat;
var ms = lib.dateTime2ms(value);
value = lib.formatDate(ms, format.replace(TEMPLATE_STRING_FORMAT_SEPARATOR, ''), false, fmt);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plots/cartesian/set_convert.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;
var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
Expand DownExpand Up@@ -954,7 +955,7 @@ module.exports = function setConvert(ax, fullLayout) {
// Fall back on default format for dummy axes that don't care about formatting
var locale = fullLayout._d3locale;
if(ax.type === 'date') {
ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
ax._dateFormat = locale ? locale.timeFormat : utcFormat;
ax._extraFormat = fullLayout._extraFormat;
}
// occasionally we need _numFormat to pass through
Expand Down
6 changes: 5 additions & 1 deletion src/plots/plots.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
'use strict';

var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');

var Registry = require('../registry');
Expand DownExpand Up@@ -723,7 +724,10 @@ function getFormatter(formatObj, separators) {
formatObj.decimal = separators.charAt(0);
formatObj.thousands = separators.charAt(1);

return d3.locale(formatObj);
return {
numberFormat: d3.locale(formatObj).numberFormat,
timeFormat: timeFormatLocale(formatObj).utcFormat
};
}

function fillMetaTextHelpers(newFullData, newFullLayout) {
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
Expand DownExpand Up@@ -5206,7 +5207,7 @@ function getZoomOutButton(gd) {
}

function getFormatter(format) {
return d3.time.format.utc(format);
return utcFormat(format);
}

describe('Test Axes.getTickformat', function() {
Expand Down
19 changes: 14 additions & 5 deletions test/jasmine/tests/lib_date_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ var calComponent = require('@src/components/calendars');
// use only the parts of world-calendars that we've imported for our tests
var calendars = require('@src/components/calendars/calendars');

var utcFormat = require('d3').time.format.utc;
var utcFormat = require('d3-time-format').utcFormat;

describe('dates', function() {
'use strict';
Expand DownExpand Up@@ -571,15 +571,24 @@ describe('dates', function() {
],
[
'%B \'%y WOY:%U DOW:%w',
'August \'12 WOY:32 DOW:1',
'August \'12 WOY:33 DOW:1',

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed bug reported in d3/d3-time-format#62.

'Mesori \'28 WOY:## DOW:##' // world-cals doesn't support U or w
],
[
'%B \'%y QOY:%q WOY:%W DOW:%u',
'August \'12 QOY:3 WOY:33 DOW:1',
'Mesori \'28 QOY:3 WOY:48 DOW:1'
],
[
'seconds: %s and milliseconds: %Q since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch',
'seconds: 1344838774 and milliseconds: 1344838774567 since UNIX epoch'
],
[
'%c && %x && .%2f .%f', // %<n>f is our addition
'Mon Aug 13 06:19:34 2012 && 08/13/2012 && .57 .5678',
'Pes Meso 7 06:19:34 1728 && 12/07/1728 && .57 .5678'
'8/13/2012, 6:19:34 AM && 8/13/2012 && .57 .5678',
'Pes Meso 7 6:19:34 AM 1728 && 12/07/1728 && .57 .5678'

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/d3/d3/blob/master/CHANGES.md#time-formats-d3-time-format
The default U.S. English locale now uses 12-hour time and a more concise representation of the date. This aligns with local convention and is consistent with date.toLocaleString in Chrome, Firefox and Node

varnow=newDate;d3.timeFormat("%c")(newDate);// "6/23/2016, 2:01:33 PM"d3.timeFormat("%x")(newDate);// "6/23/2016"d3.timeFormat("%X")(newDate);// "2:01:38 PM"

]

].forEach(function(v) {
var fmt = v[0];
var expectedGregorian = v[1];
Expand Down
3 changes: 2 additions & 1 deletion test/jasmine/tests/localize_test.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ var _ = Lib._;
var Registry = require('@src/registry');

var d3 = require('d3');
var utcFormat = require('d3-time-format').utcFormat;

var Plotly = require('@lib');
var createGraphDiv = require('../assets/create_graph_div');
Expand DownExpand Up@@ -236,7 +237,7 @@ describe('localization', function() {
expect(firstYLabel()).toBe('0~5');
var d0 = new Date(0); // thursday, Jan 1 1970 (UTC)
// sanity check that d0 is what we think...
expect(d3.time.format.utc('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
expect(utcFormat('%a %b %A %B')(d0)).toBe('Thu Jan Thursday January');
// full names were not overridden, so fall back on english
expect(gd._fullLayout.xaxis._dateFormat('%a %b %A %B')(d0)).toBe('t !1 Thursday January');
})
Expand Down