Time.js 24 KB

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