@windborne/grapher 1.0.40 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windborne/grapher",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "Graphing library",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/bundle.esm.js",
@@ -48,7 +48,7 @@ const DATE_TIME_FORMATTERS = {};
48
48
  * @param {Date} sampleDate - a date to use in the conversions, since it can be time-of-year dependent with Daylight Savings Time
49
49
  * @return {number|null}
50
50
  */
51
- function timezoneToOffsetMS(timeZone, sampleDate) {
51
+ export function timezoneToOffsetMS(timeZone, sampleDate) {
52
52
  try { // formats are finicky, so give up rather than abort rendering
53
53
  let datetimeFormatter = DATE_TIME_FORMATTERS[timeZone];
54
54
  if (!datetimeFormatter) {
@@ -1,4 +1,4 @@
1
- import {startOfDayInTimezone} from './format';
1
+ import {startOfDayInTimezone, timezoneToOffsetMS} from './format';
2
2
 
3
3
  function placeTick(trueValue, {scale, min, max, inverted, totalSize, precision, formatter, dates, justTime, justDate, formatOptions={} }, opts={}) {
4
4
  let scaledValue = trueValue;
@@ -284,17 +284,39 @@ function placeTimeOnlyGrid({ min, max, precision, expectedLabelSize, labelPaddin
284
284
  let currentDate = new Date(min);
285
285
 
286
286
  if (unit === 'h') {
287
- currentDate.setMinutes(0, 0, 0);
288
287
  if (amount === 24) {
289
- currentDate.setHours(0);
290
- } else if (amount === 12) {
291
- const currentHour = currentDate.getHours();
292
- const alignedHour = currentHour < 12 ? 0 : 12;
293
- currentDate.setHours(alignedHour);
288
+ currentDate = startOfDayInTimezone(currentDate, formatOptions.timeZone);
294
289
  } else {
295
- const currentHour = currentDate.getHours();
296
- const alignedHour = Math.floor(currentHour / amount) * amount;
297
- currentDate.setHours(alignedHour);
290
+ const offset = formatOptions.timeZone ? timezoneToOffsetMS(formatOptions.timeZone, currentDate) : 0;
291
+ const localOffset = timezoneToOffsetMS('local', currentDate);
292
+
293
+ if (offset !== null && localOffset !== null) {
294
+ const adjustedDate = new Date(currentDate.valueOf() + offset - localOffset);
295
+ adjustedDate.setMinutes(0, 0, 0);
296
+
297
+ if (amount === 12) {
298
+ const currentHour = adjustedDate.getHours();
299
+ const alignedHour = currentHour < 12 ? 0 : 12;
300
+ adjustedDate.setHours(alignedHour);
301
+ } else {
302
+ const currentHour = adjustedDate.getHours();
303
+ const alignedHour = Math.floor(currentHour / amount) * amount;
304
+ adjustedDate.setHours(alignedHour);
305
+ }
306
+
307
+ currentDate = new Date(adjustedDate.valueOf() - offset + localOffset);
308
+ } else {
309
+ currentDate.setMinutes(0, 0, 0);
310
+ if (amount === 12) {
311
+ const currentHour = currentDate.getHours();
312
+ const alignedHour = currentHour < 12 ? 0 : 12;
313
+ currentDate.setHours(alignedHour);
314
+ } else {
315
+ const currentHour = currentDate.getHours();
316
+ const alignedHour = Math.floor(currentHour / amount) * amount;
317
+ currentDate.setHours(alignedHour);
318
+ }
319
+ }
298
320
  }
299
321
  } else if (unit === 'm') {
300
322
  currentDate.setSeconds(0, 0);
@@ -409,7 +431,6 @@ function placeDateOnlyGrid({ min, max, precision, expectedLabelSize, labelPaddin
409
431
  currentDate.setDate(1);
410
432
  } else if (unit === 'd') {
411
433
  currentDate = startOfDayInTimezone(currentDate, formatOptions.timeZone);
412
- currentDate.setHours(0, 0, 0, 0);
413
434
  }
414
435
 
415
436
  while (currentDate < max) {