Node-Red configuration
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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