Time.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /* *
  2. *
  3. * (c) 2010-2021 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. 'use strict';
  11. import H from './Globals.js';
  12. var win = H.win;
  13. import U from './Utilities.js';
  14. var defined = U.defined, error = U.error, extend = U.extend, isObject = U.isObject, merge = U.merge, objectEach = U.objectEach, pad = U.pad, pick = U.pick, splat = U.splat, timeUnits = U.timeUnits;
  15. /**
  16. * Normalized interval.
  17. *
  18. * @interface Highcharts.TimeNormalizedObject
  19. */ /**
  20. * The count.
  21. *
  22. * @name Highcharts.TimeNormalizedObject#count
  23. * @type {number}
  24. */ /**
  25. * The interval in axis values (ms).
  26. *
  27. * @name Highcharts.TimeNormalizedObject#unitRange
  28. * @type {number}
  29. */
  30. /**
  31. * Function of an additional date format specifier.
  32. *
  33. * @callback Highcharts.TimeFormatCallbackFunction
  34. *
  35. * @param {number} timestamp
  36. * The time to format.
  37. *
  38. * @return {string}
  39. * The formatted portion of the date.
  40. */
  41. /**
  42. * Time ticks.
  43. *
  44. * @interface Highcharts.AxisTickPositionsArray
  45. * @extends global.Array<number>
  46. */ /**
  47. * @name Highcharts.AxisTickPositionsArray#info
  48. * @type {Highcharts.TimeTicksInfoObject|undefined}
  49. */
  50. /**
  51. * A callback to return the time zone offset for a given datetime. It
  52. * takes the timestamp in terms of milliseconds since January 1 1970,
  53. * and returns the timezone offset in minutes. This provides a hook
  54. * for drawing time based charts in specific time zones using their
  55. * local DST crossover dates, with the help of external libraries.
  56. *
  57. * @callback Highcharts.TimezoneOffsetCallbackFunction
  58. *
  59. * @param {number} timestamp
  60. * Timestamp in terms of milliseconds since January 1 1970.
  61. *
  62. * @return {number}
  63. * Timezone offset in minutes.
  64. */
  65. /**
  66. * Allows to manually load the `moment.js` library from Highcharts options
  67. * instead of the `window`.
  68. * In case of loading the library from a `script` tag,
  69. * this option is not needed, it will be loaded from there by default.
  70. *
  71. * @type {function}
  72. * @since 8.2.0
  73. * @apioption time.moment
  74. */
  75. ''; // detach doclets above
  76. /* eslint-disable no-invalid-this, valid-jsdoc */
  77. /**
  78. * The Time class. Time settings are applied in general for each page using
  79. * `Highcharts.setOptions`, or individually for each Chart item through the
  80. * [time](https://api.highcharts.com/highcharts/time) options set.
  81. *
  82. * The Time object is available from {@link Highcharts.Chart#time},
  83. * which refers to `Highcharts.time` if no individual time settings are
  84. * applied.
  85. *
  86. * @example
  87. * // Apply time settings globally
  88. * Highcharts.setOptions({
  89. * time: {
  90. * timezone: 'Europe/London'
  91. * }
  92. * });
  93. *
  94. * // Apply time settings by instance
  95. * var chart = Highcharts.chart('container', {
  96. * time: {
  97. * timezone: 'America/New_York'
  98. * },
  99. * series: [{
  100. * data: [1, 4, 3, 5]
  101. * }]
  102. * });
  103. *
  104. * // Use the Time object
  105. * console.log(
  106. * 'Current time in New York',
  107. * chart.time.dateFormat('%Y-%m-%d %H:%M:%S', Date.now())
  108. * );
  109. *
  110. * @since 6.0.5
  111. *
  112. * @class
  113. * @name Highcharts.Time
  114. *
  115. * @param {Highcharts.TimeOptions} options
  116. * Time options as defined in [chart.options.time](/highcharts/time).
  117. */
  118. var Time = /** @class */ (function () {
  119. /* *
  120. *
  121. * Constructors
  122. *
  123. * */
  124. function Time(options) {
  125. /* *
  126. *
  127. * Properties
  128. *
  129. * */
  130. this.options = {};
  131. this.useUTC = false;
  132. this.variableTimezone = false;
  133. this.Date = win.Date;
  134. /**
  135. * Get the time zone offset based on the current timezone information as
  136. * set in the global options.
  137. *
  138. * @function Highcharts.Time#getTimezoneOffset
  139. *
  140. * @param {number} timestamp
  141. * The JavaScript timestamp to inspect.
  142. *
  143. * @return {number}
  144. * The timezone offset in minutes compared to UTC.
  145. */
  146. this.getTimezoneOffset = this.timezoneOffsetFunction();
  147. this.update(options);
  148. }
  149. /* *
  150. *
  151. * Functions
  152. *
  153. * */
  154. /**
  155. * Time units used in `Time.get` and `Time.set`
  156. *
  157. * @typedef {"Date"|"Day"|"FullYear"|"Hours"|"Milliseconds"|"Minutes"|"Month"|"Seconds"} Highcharts.TimeUnitValue
  158. */
  159. /**
  160. * Get the value of a date object in given units, and subject to the Time
  161. * object's current timezone settings. This function corresponds directly to
  162. * JavaScripts `Date.getXXX / Date.getUTCXXX`, so instead of calling
  163. * `date.getHours()` or `date.getUTCHours()` we will call
  164. * `time.get('Hours')`.
  165. *
  166. * @function Highcharts.Time#get
  167. *
  168. * @param {Highcharts.TimeUnitValue} unit
  169. * @param {Date} date
  170. *
  171. * @return {number}
  172. * The given time unit
  173. */
  174. Time.prototype.get = function (unit, date) {
  175. if (this.variableTimezone || this.timezoneOffset) {
  176. var realMs = date.getTime();
  177. var ms = realMs - this.getTimezoneOffset(date);
  178. date.setTime(ms); // Temporary adjust to timezone
  179. var ret = date['getUTC' + unit]();
  180. date.setTime(realMs); // Reset
  181. return ret;
  182. }
  183. // UTC time with no timezone handling
  184. if (this.useUTC) {
  185. return date['getUTC' + unit]();
  186. }
  187. // Else, local time
  188. return date['get' + unit]();
  189. };
  190. /**
  191. * Set the value of a date object in given units, and subject to the Time
  192. * object's current timezone settings. This function corresponds directly to
  193. * JavaScripts `Date.setXXX / Date.setUTCXXX`, so instead of calling
  194. * `date.setHours(0)` or `date.setUTCHours(0)` we will call
  195. * `time.set('Hours', 0)`.
  196. *
  197. * @function Highcharts.Time#set
  198. *
  199. * @param {Highcharts.TimeUnitValue} unit
  200. * @param {Date} date
  201. * @param {number} value
  202. *
  203. * @return {number}
  204. * The epoch milliseconds of the updated date
  205. */
  206. Time.prototype.set = function (unit, date, value) {
  207. // UTC time with timezone handling
  208. if (this.variableTimezone || this.timezoneOffset) {
  209. // For lower order time units, just set it directly using UTC
  210. // time
  211. if (unit === 'Milliseconds' ||
  212. unit === 'Seconds' ||
  213. (unit === 'Minutes' && this.getTimezoneOffset(date) % 3600000 === 0) // #13961
  214. ) {
  215. return date['setUTC' + unit](value);
  216. }
  217. // Higher order time units need to take the time zone into
  218. // account
  219. // Adjust by timezone
  220. var offset = this.getTimezoneOffset(date);
  221. var ms = date.getTime() - offset;
  222. date.setTime(ms);
  223. date['setUTC' + unit](value);
  224. var newOffset = this.getTimezoneOffset(date);
  225. ms = date.getTime() + newOffset;
  226. return date.setTime(ms);
  227. }
  228. // UTC time with no timezone handling
  229. if (this.useUTC) {
  230. return date['setUTC' + unit](value);
  231. }
  232. // Else, local time
  233. return date['set' + unit](value);
  234. };
  235. /**
  236. * Update the Time object with current options. It is called internally on
  237. * initializing Highcharts, after running `Highcharts.setOptions` and on
  238. * `Chart.update`.
  239. *
  240. * @private
  241. * @function Highcharts.Time#update
  242. *
  243. * @param {Highcharts.TimeOptions} options
  244. *
  245. * @return {void}
  246. */
  247. Time.prototype.update = function (options) {
  248. var useUTC = pick(options && options.useUTC, true), time = this;
  249. this.options = options = merge(true, this.options || {}, options);
  250. // Allow using a different Date class
  251. this.Date = options.Date || win.Date || Date;
  252. this.useUTC = useUTC;
  253. this.timezoneOffset = (useUTC && options.timezoneOffset);
  254. this.getTimezoneOffset = this.timezoneOffsetFunction();
  255. /*
  256. * The time object has options allowing for variable time zones, meaning
  257. * the axis ticks or series data needs to consider this.
  258. */
  259. this.variableTimezone = useUTC && !!(options.getTimezoneOffset ||
  260. options.timezone);
  261. };
  262. /**
  263. * Make a time and returns milliseconds. Interprets the inputs as UTC time,
  264. * local time or a specific timezone time depending on the current time
  265. * settings.
  266. *
  267. * @function Highcharts.Time#makeTime
  268. *
  269. * @param {number} year
  270. * The year
  271. *
  272. * @param {number} month
  273. * The month. Zero-based, so January is 0.
  274. *
  275. * @param {number} [date=1]
  276. * The day of the month
  277. *
  278. * @param {number} [hours=0]
  279. * The hour of the day, 0-23.
  280. *
  281. * @param {number} [minutes=0]
  282. * The minutes
  283. *
  284. * @param {number} [seconds=0]
  285. * The seconds
  286. *
  287. * @return {number}
  288. * The time in milliseconds since January 1st 1970.
  289. */
  290. Time.prototype.makeTime = function (year, month, date, hours, minutes, seconds) {
  291. var d, offset, newOffset;
  292. if (this.useUTC) {
  293. d = this.Date.UTC.apply(0, arguments);
  294. offset = this.getTimezoneOffset(d);
  295. d += offset;
  296. newOffset = this.getTimezoneOffset(d);
  297. if (offset !== newOffset) {
  298. d += newOffset - offset;
  299. // A special case for transitioning from summer time to winter time.
  300. // When the clock is set back, the same time is repeated twice, i.e.
  301. // 02:30 am is repeated since the clock is set back from 3 am to
  302. // 2 am. We need to make the same time as local Date does.
  303. }
  304. else if (offset - 36e5 === this.getTimezoneOffset(d - 36e5) &&
  305. !H.isSafari) {
  306. d -= 36e5;
  307. }
  308. }
  309. else {
  310. d = new this.Date(year, month, pick(date, 1), pick(hours, 0), pick(minutes, 0), pick(seconds, 0)).getTime();
  311. }
  312. return d;
  313. };
  314. /**
  315. * Sets the getTimezoneOffset function. If the `timezone` option is set, a
  316. * default getTimezoneOffset function with that timezone is returned. If
  317. * a `getTimezoneOffset` option is defined, it is returned. If neither are
  318. * specified, the function using the `timezoneOffset` option or 0 offset is
  319. * returned.
  320. *
  321. * @private
  322. * @function Highcharts.Time#timezoneOffsetFunction
  323. *
  324. * @return {Function}
  325. * A getTimezoneOffset function
  326. */
  327. Time.prototype.timezoneOffsetFunction = function () {
  328. var time = this, options = this.options, moment = options.moment || win.moment;
  329. if (!this.useUTC) {
  330. return function (timestamp) {
  331. return new Date(timestamp.toString()).getTimezoneOffset() * 60000;
  332. };
  333. }
  334. if (options.timezone) {
  335. if (!moment) {
  336. // getTimezoneOffset-function stays undefined because it depends
  337. // on Moment.js
  338. error(25);
  339. }
  340. else {
  341. return function (timestamp) {
  342. return -moment.tz(timestamp, options.timezone).utcOffset() * 60000;
  343. };
  344. }
  345. }
  346. // If not timezone is set, look for the getTimezoneOffset callback
  347. if (this.useUTC && options.getTimezoneOffset) {
  348. return function (timestamp) {
  349. return options.getTimezoneOffset(timestamp.valueOf()) * 60000;
  350. };
  351. }
  352. // Last, use the `timezoneOffset` option if set
  353. return function () {
  354. return (time.timezoneOffset || 0) * 60000;
  355. };
  356. };
  357. /**
  358. * Formats a JavaScript date timestamp (milliseconds since Jan 1st 1970)
  359. * into a human readable date string. The available format keys are listed
  360. * below. Additional formats can be given in the
  361. * {@link Highcharts.dateFormats} hook.
  362. *
  363. * Supported format keys:
  364. * - `%a`: Short weekday, like 'Mon'
  365. * - `%A`: Long weekday, like 'Monday'
  366. * - `%d`: Two digit day of the month, 01 to 31
  367. * - `%e`: Day of the month, 1 through 31
  368. * - `%w`: Day of the week, 0 through 6
  369. * - `%b`: Short month, like 'Jan'
  370. * - `%B`: Long month, like 'January'
  371. * - `%m`: Two digit month number, 01 through 12
  372. * - `%y`: Two digits year, like 09 for 2009
  373. * - `%Y`: Four digits year, like 2009
  374. * - `%H`: Two digits hours in 24h format, 00 through 23
  375. * - `%k`: Hours in 24h format, 0 through 23
  376. * - `%I`: Two digits hours in 12h format, 00 through 11
  377. * - `%l`: Hours in 12h format, 1 through 12
  378. * - `%M`: Two digits minutes, 00 through 59
  379. * - `%p`: Upper case AM or PM
  380. * - `%P`: Lower case AM or PM
  381. * - `%S`: Two digits seconds, 00 through 59
  382. * - `%L`: Milliseconds (naming from Ruby)
  383. *
  384. * @example
  385. * const time = new Highcharts.Time();
  386. * const s = time.dateFormat('%Y-%m-%d %H:%M:%S', Date.UTC(2020, 0, 1));
  387. * console.log(s); // => 2020-01-01 00:00:00
  388. *
  389. * @function Highcharts.Time#dateFormat
  390. *
  391. * @param {string} format
  392. * The desired format where various time representations are
  393. * prefixed with %.
  394. *
  395. * @param {number} [timestamp]
  396. * The JavaScript timestamp.
  397. *
  398. * @param {boolean} [capitalize=false]
  399. * Upper case first letter in the return.
  400. *
  401. * @return {string}
  402. * The formatted date.
  403. */
  404. Time.prototype.dateFormat = function (format, timestamp, capitalize) {
  405. var _a;
  406. if (!defined(timestamp) || isNaN(timestamp)) {
  407. return ((_a = H.defaultOptions.lang) === null || _a === void 0 ? void 0 : _a.invalidDate) || '';
  408. }
  409. format = pick(format, '%Y-%m-%d %H:%M:%S');
  410. var time = this, date = new this.Date(timestamp),
  411. // get the basic time values
  412. hours = this.get('Hours', date), day = this.get('Day', date), dayOfMonth = this.get('Date', date), month = this.get('Month', date), fullYear = this.get('FullYear', date), lang = H.defaultOptions.lang, langWeekdays = lang === null || lang === void 0 ? void 0 : lang.weekdays, shortWeekdays = lang === null || lang === void 0 ? void 0 : lang.shortWeekdays,
  413. // List all format keys. Custom formats can be added from the
  414. // outside.
  415. replacements = extend({
  416. // Day
  417. // Short weekday, like 'Mon'
  418. a: shortWeekdays ?
  419. shortWeekdays[day] :
  420. langWeekdays[day].substr(0, 3),
  421. // Long weekday, like 'Monday'
  422. A: langWeekdays[day],
  423. // Two digit day of the month, 01 to 31
  424. d: pad(dayOfMonth),
  425. // Day of the month, 1 through 31
  426. e: pad(dayOfMonth, 2, ' '),
  427. // Day of the week, 0 through 6
  428. w: day,
  429. // Week (none implemented)
  430. // 'W': weekNumber(),
  431. // Month
  432. // Short month, like 'Jan'
  433. b: lang.shortMonths[month],
  434. // Long month, like 'January'
  435. B: lang.months[month],
  436. // Two digit month number, 01 through 12
  437. m: pad(month + 1),
  438. // Month number, 1 through 12 (#8150)
  439. o: month + 1,
  440. // Year
  441. // Two digits year, like 09 for 2009
  442. y: fullYear.toString().substr(2, 2),
  443. // Four digits year, like 2009
  444. Y: fullYear,
  445. // Time
  446. // Two digits hours in 24h format, 00 through 23
  447. H: pad(hours),
  448. // Hours in 24h format, 0 through 23
  449. k: hours,
  450. // Two digits hours in 12h format, 00 through 11
  451. I: pad((hours % 12) || 12),
  452. // Hours in 12h format, 1 through 12
  453. l: (hours % 12) || 12,
  454. // Two digits minutes, 00 through 59
  455. M: pad(this.get('Minutes', date)),
  456. // Upper case AM or PM
  457. p: hours < 12 ? 'AM' : 'PM',
  458. // Lower case AM or PM
  459. P: hours < 12 ? 'am' : 'pm',
  460. // Two digits seconds, 00 through 59
  461. S: pad(date.getSeconds()),
  462. // Milliseconds (naming from Ruby)
  463. L: pad(Math.floor(timestamp % 1000), 3)
  464. }, H.dateFormats);
  465. // Do the replaces
  466. objectEach(replacements, function (val, key) {
  467. // Regex would do it in one line, but this is faster
  468. while (format.indexOf('%' + key) !== -1) {
  469. format = format.replace('%' + key, typeof val === 'function' ? val.call(time, timestamp) : val);
  470. }
  471. });
  472. // Optionally capitalize the string and return
  473. return capitalize ?
  474. (format.substr(0, 1).toUpperCase() +
  475. format.substr(1)) :
  476. format;
  477. };
  478. /**
  479. * Resolve legacy formats of dateTimeLabelFormats (strings and arrays) into
  480. * an object.
  481. * @private
  482. * @param {string|Array<T>|Highcharts.Dictionary<T>} f - General format description
  483. * @return {Highcharts.Dictionary<T>} - The object definition
  484. */
  485. Time.prototype.resolveDTLFormat = function (f) {
  486. if (!isObject(f, true)) { // check for string or array
  487. f = splat(f);
  488. return {
  489. main: f[0],
  490. from: f[1],
  491. to: f[2]
  492. };
  493. }
  494. return f;
  495. };
  496. /**
  497. * Return an array with time positions distributed on round time values
  498. * right and right after min and max. Used in datetime axes as well as for
  499. * grouping data on a datetime axis.
  500. *
  501. * @function Highcharts.Time#getTimeTicks
  502. *
  503. * @param {Highcharts.TimeNormalizedObject} normalizedInterval
  504. * The interval in axis values (ms) and the count
  505. *
  506. * @param {number} [min]
  507. * The minimum in axis values
  508. *
  509. * @param {number} [max]
  510. * The maximum in axis values
  511. *
  512. * @param {number} [startOfWeek=1]
  513. *
  514. * @return {Highcharts.AxisTickPositionsArray}
  515. */
  516. Time.prototype.getTimeTicks = function (normalizedInterval, min, max, startOfWeek) {
  517. var time = this, Date = time.Date, tickPositions = [], i, higherRanks = {}, minYear, // used in months and years as a basis for Date.UTC()
  518. // When crossing DST, use the max. Resolves #6278.
  519. minDate = new Date(min), interval = normalizedInterval.unitRange, count = normalizedInterval.count || 1, variableDayLength, minDay;
  520. startOfWeek = pick(startOfWeek, 1);
  521. if (defined(min)) { // #1300
  522. time.set('Milliseconds', minDate, interval >= timeUnits.second ?
  523. 0 : // #3935
  524. count * Math.floor(time.get('Milliseconds', minDate) / count)); // #3652, #3654
  525. if (interval >= timeUnits.second) { // second
  526. time.set('Seconds', minDate, interval >= timeUnits.minute ?
  527. 0 : // #3935
  528. count * Math.floor(time.get('Seconds', minDate) / count));
  529. }
  530. if (interval >= timeUnits.minute) { // minute
  531. time.set('Minutes', minDate, interval >= timeUnits.hour ?
  532. 0 :
  533. count * Math.floor(time.get('Minutes', minDate) / count));
  534. }
  535. if (interval >= timeUnits.hour) { // hour
  536. time.set('Hours', minDate, interval >= timeUnits.day ?
  537. 0 :
  538. count * Math.floor(time.get('Hours', minDate) / count));
  539. }
  540. if (interval >= timeUnits.day) { // day
  541. time.set('Date', minDate, interval >= timeUnits.month ?
  542. 1 :
  543. Math.max(1, count * Math.floor(time.get('Date', minDate) / count)));
  544. }
  545. if (interval >= timeUnits.month) { // month
  546. time.set('Month', minDate, interval >= timeUnits.year ? 0 :
  547. count * Math.floor(time.get('Month', minDate) / count));
  548. minYear = time.get('FullYear', minDate);
  549. }
  550. if (interval >= timeUnits.year) { // year
  551. minYear -= minYear % count;
  552. time.set('FullYear', minDate, minYear);
  553. }
  554. // week is a special case that runs outside the hierarchy
  555. if (interval === timeUnits.week) {
  556. // get start of current week, independent of count
  557. minDay = time.get('Day', minDate);
  558. time.set('Date', minDate, (time.get('Date', minDate) -
  559. minDay + startOfWeek +
  560. // We don't want to skip days that are before
  561. // startOfWeek (#7051)
  562. (minDay < startOfWeek ? -7 : 0)));
  563. }
  564. // Get basics for variable time spans
  565. minYear = time.get('FullYear', minDate);
  566. var minMonth = time.get('Month', minDate), minDateDate = time.get('Date', minDate), minHours = time.get('Hours', minDate);
  567. // Redefine min to the floored/rounded minimum time (#7432)
  568. min = minDate.getTime();
  569. // Handle local timezone offset
  570. if ((time.variableTimezone || !time.useUTC) && defined(max)) {
  571. // Detect whether we need to take the DST crossover into
  572. // consideration. If we're crossing over DST, the day length may
  573. // be 23h or 25h and we need to compute the exact clock time for
  574. // each tick instead of just adding hours. This comes at a cost,
  575. // so first we find out if it is needed (#4951).
  576. variableDayLength = (
  577. // Long range, assume we're crossing over.
  578. max - min > 4 * timeUnits.month ||
  579. // Short range, check if min and max are in different time
  580. // zones.
  581. time.getTimezoneOffset(min) !==
  582. time.getTimezoneOffset(max));
  583. }
  584. // Iterate and add tick positions at appropriate values
  585. var t = minDate.getTime();
  586. i = 1;
  587. while (t < max) {
  588. tickPositions.push(t);
  589. // if the interval is years, use Date.UTC to increase years
  590. if (interval === timeUnits.year) {
  591. t = time.makeTime(minYear + i * count, 0);
  592. // if the interval is months, use Date.UTC to increase months
  593. }
  594. else if (interval === timeUnits.month) {
  595. t = time.makeTime(minYear, minMonth + i * count);
  596. // if we're using global time, the interval is not fixed as it
  597. // jumps one hour at the DST crossover
  598. }
  599. else if (variableDayLength &&
  600. (interval === timeUnits.day || interval === timeUnits.week)) {
  601. t = time.makeTime(minYear, minMonth, minDateDate +
  602. i * count * (interval === timeUnits.day ? 1 : 7));
  603. }
  604. else if (variableDayLength &&
  605. interval === timeUnits.hour &&
  606. count > 1) {
  607. // make sure higher ranks are preserved across DST (#6797,
  608. // #7621)
  609. t = time.makeTime(minYear, minMonth, minDateDate, minHours + i * count);
  610. // else, the interval is fixed and we use simple addition
  611. }
  612. else {
  613. t += interval * count;
  614. }
  615. i++;
  616. }
  617. // push the last time
  618. tickPositions.push(t);
  619. // Handle higher ranks. Mark new days if the time is on midnight
  620. // (#950, #1649, #1760, #3349). Use a reasonable dropout threshold
  621. // to prevent looping over dense data grouping (#6156).
  622. if (interval <= timeUnits.hour && tickPositions.length < 10000) {
  623. tickPositions.forEach(function (t) {
  624. if (
  625. // Speed optimization, no need to run dateFormat unless
  626. // we're on a full or half hour
  627. t % 1800000 === 0 &&
  628. // Check for local or global midnight
  629. time.dateFormat('%H%M%S%L', t) === '000000000') {
  630. higherRanks[t] = 'day';
  631. }
  632. });
  633. }
  634. }
  635. // record information on the chosen unit - for dynamic label formatter
  636. tickPositions.info = extend(normalizedInterval, {
  637. higherRanks: higherRanks,
  638. totalRange: interval * count
  639. });
  640. return tickPositions;
  641. };
  642. return Time;
  643. }());
  644. H.Time = Time;
  645. export default H.Time;