Time.js 24 KB

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