Node-Red configuration
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

chartjs-adapter-luxon.umd.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*!
  2. * chartjs-adapter-luxon v1.3.1
  3. * https://www.chartjs.org
  4. * (c) 2023 chartjs-adapter-luxon Contributors
  5. * Released under the MIT license
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('chart.js'), require('luxon')) :
  9. typeof define === 'function' && define.amd ? define(['chart.js', 'luxon'], factory) :
  10. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Chart, global.luxon));
  11. })(this, (function (chart_js, luxon) { 'use strict';
  12. const FORMATS = {
  13. datetime: luxon.DateTime.DATETIME_MED_WITH_SECONDS,
  14. millisecond: 'h:mm:ss.SSS a',
  15. second: luxon.DateTime.TIME_WITH_SECONDS,
  16. minute: luxon.DateTime.TIME_SIMPLE,
  17. hour: {hour: 'numeric'},
  18. day: {day: 'numeric', month: 'short'},
  19. week: 'DD',
  20. month: {month: 'short', year: 'numeric'},
  21. quarter: "'Q'q - yyyy",
  22. year: {year: 'numeric'}
  23. };
  24. chart_js._adapters._date.override({
  25. _id: 'luxon', // DEBUG
  26. /**
  27. * @private
  28. */
  29. _create: function(time) {
  30. return luxon.DateTime.fromMillis(time, this.options);
  31. },
  32. init(chartOptions) {
  33. if (!this.options.locale) {
  34. this.options.locale = chartOptions.locale;
  35. }
  36. },
  37. formats: function() {
  38. return FORMATS;
  39. },
  40. parse: function(value, format) {
  41. const options = this.options;
  42. const type = typeof value;
  43. if (value === null || type === 'undefined') {
  44. return null;
  45. }
  46. if (type === 'number') {
  47. value = this._create(value);
  48. } else if (type === 'string') {
  49. if (typeof format === 'string') {
  50. value = luxon.DateTime.fromFormat(value, format, options);
  51. } else {
  52. value = luxon.DateTime.fromISO(value, options);
  53. }
  54. } else if (value instanceof Date) {
  55. value = luxon.DateTime.fromJSDate(value, options);
  56. } else if (type === 'object' && !(value instanceof luxon.DateTime)) {
  57. value = luxon.DateTime.fromObject(value, options);
  58. }
  59. return value.isValid ? value.valueOf() : null;
  60. },
  61. format: function(time, format) {
  62. const datetime = this._create(time);
  63. return typeof format === 'string'
  64. ? datetime.toFormat(format)
  65. : datetime.toLocaleString(format);
  66. },
  67. add: function(time, amount, unit) {
  68. const args = {};
  69. args[unit] = amount;
  70. return this._create(time).plus(args).valueOf();
  71. },
  72. diff: function(max, min, unit) {
  73. return this._create(max).diff(this._create(min)).as(unit).valueOf();
  74. },
  75. startOf: function(time, unit, weekday) {
  76. if (unit === 'isoWeek') {
  77. weekday = Math.trunc(Math.min(Math.max(0, weekday), 6));
  78. const dateTime = this._create(time);
  79. return dateTime.minus({days: (dateTime.weekday - weekday + 7) % 7}).startOf('day').valueOf();
  80. }
  81. return unit ? this._create(time).startOf(unit).valueOf() : time;
  82. },
  83. endOf: function(time, unit) {
  84. return this._create(time).endOf(unit).valueOf();
  85. }
  86. });
  87. }));