graphein 0.16.1 → 0.16.2

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/dist/index.js CHANGED
@@ -219,35 +219,43 @@ function fixedDuration(interval) {
219
219
  }
220
220
  }
221
221
  function floorFixed(value, interval) {
222
- const duration = fixedDuration(interval);
223
- if (interval.unit !== "week") {
224
- return Math.floor(value / duration) * duration;
225
- }
226
222
  const date = new Date(value);
227
- const midnight = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
228
- const day = new Date(midnight).getUTCDay();
229
- const weekStart = midnight - day * DAY;
230
- return weekStart - Math.floor((weekStart % duration + duration) % duration);
223
+ if (interval.unit === "day") {
224
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
225
+ }
226
+ if (interval.unit === "week") {
227
+ const day = date.getDay();
228
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - day).getTime();
229
+ }
230
+ const duration = fixedDuration(interval);
231
+ return Math.floor(value / duration) * duration;
231
232
  }
232
233
  function addFixed(value, interval) {
234
+ const date = new Date(value);
235
+ if (interval.unit === "day") {
236
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + interval.step).getTime();
237
+ }
238
+ if (interval.unit === "week") {
239
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 7 * interval.step).getTime();
240
+ }
233
241
  return value + fixedDuration(interval);
234
242
  }
235
243
  function floorMonth(value, step) {
236
244
  const date = new Date(value);
237
- const month = Math.floor(date.getUTCMonth() / step) * step;
238
- return Date.UTC(date.getUTCFullYear(), month, 1);
245
+ const month = Math.floor(date.getMonth() / step) * step;
246
+ return new Date(date.getFullYear(), month, 1).getTime();
239
247
  }
240
248
  function floorYear(value, step) {
241
249
  const date = new Date(value);
242
- const year = Math.floor(date.getUTCFullYear() / step) * step;
243
- return Date.UTC(year, 0, 1);
250
+ const year = Math.floor(date.getFullYear() / step) * step;
251
+ return new Date(year, 0, 1).getTime();
244
252
  }
245
253
  function addCalendar(value, interval) {
246
254
  const date = new Date(value);
247
255
  if (interval.unit === "month") {
248
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + interval.step, 1);
256
+ return new Date(date.getFullYear(), date.getMonth() + interval.step, 1).getTime();
249
257
  }
250
- return Date.UTC(date.getUTCFullYear() + interval.step, 0, 1);
258
+ return new Date(date.getFullYear() + interval.step, 0, 1).getTime();
251
259
  }
252
260
  function floorTime(value, interval) {
253
261
  if (interval.unit === "month") {
@@ -295,17 +303,17 @@ function timeTickFormat(values) {
295
303
  const span = ordered.length > 1 ? Math.abs(ordered[1] - ordered[0]) : 0;
296
304
  return (time) => {
297
305
  const date = new Date(time);
298
- const year = date.getUTCFullYear();
299
- const month = MONTH_NAMES[date.getUTCMonth()];
300
- const day = date.getUTCDate();
301
- const hours = pad2(date.getUTCHours());
302
- const minutes = pad2(date.getUTCMinutes());
303
- const seconds = pad2(date.getUTCSeconds());
306
+ const year = date.getFullYear();
307
+ const month = MONTH_NAMES[date.getMonth()];
308
+ const day = date.getDate();
309
+ const hours = pad2(date.getHours());
310
+ const minutes = pad2(date.getMinutes());
311
+ const seconds = pad2(date.getSeconds());
304
312
  if (span >= YEAR * 0.8) {
305
313
  return String(year);
306
314
  }
307
315
  if (span >= MONTH * 0.8) {
308
- return ordered.some((tick) => new Date(tick).getUTCFullYear() !== year) ? `${month} ${year}` : month;
316
+ return ordered.some((tick) => new Date(tick).getFullYear() !== year) ? `${month} ${year}` : month;
309
317
  }
310
318
  if (span >= DAY * 0.8) {
311
319
  return `${month} ${day}`;