Node-Red configuration
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. import * as C from './constant';
  2. import en from './locale/en';
  3. import U from './utils';
  4. var L = 'en'; // global locale
  5. var Ls = {}; // global loaded locale
  6. Ls[L] = en;
  7. var isDayjs = function isDayjs(d) {
  8. return d instanceof Dayjs;
  9. }; // eslint-disable-line no-use-before-define
  10. var parseLocale = function parseLocale(preset, object, isLocal) {
  11. var l;
  12. if (!preset) return L;
  13. if (typeof preset === 'string') {
  14. var presetLower = preset.toLowerCase();
  15. if (Ls[presetLower]) {
  16. l = presetLower;
  17. }
  18. if (object) {
  19. Ls[presetLower] = object;
  20. l = presetLower;
  21. }
  22. var presetSplit = preset.split('-');
  23. if (!l && presetSplit.length > 1) {
  24. return parseLocale(presetSplit[0]);
  25. }
  26. } else {
  27. var name = preset.name;
  28. Ls[name] = preset;
  29. l = name;
  30. }
  31. if (!isLocal && l) L = l;
  32. return l || !isLocal && L;
  33. };
  34. var dayjs = function dayjs(date, c) {
  35. if (isDayjs(date)) {
  36. return date.clone();
  37. } // eslint-disable-next-line no-nested-ternary
  38. var cfg = typeof c === 'object' ? c : {};
  39. cfg.date = date;
  40. cfg.args = arguments; // eslint-disable-line prefer-rest-params
  41. return new Dayjs(cfg); // eslint-disable-line no-use-before-define
  42. };
  43. var wrapper = function wrapper(date, instance) {
  44. return dayjs(date, {
  45. locale: instance.$L,
  46. utc: instance.$u,
  47. x: instance.$x,
  48. $offset: instance.$offset // todo: refactor; do not use this.$offset in you code
  49. });
  50. };
  51. var Utils = U; // for plugin use
  52. Utils.l = parseLocale;
  53. Utils.i = isDayjs;
  54. Utils.w = wrapper;
  55. var parseDate = function parseDate(cfg) {
  56. var date = cfg.date,
  57. utc = cfg.utc;
  58. if (date === null) return new Date(NaN); // null is invalid
  59. if (Utils.u(date)) return new Date(); // today
  60. if (date instanceof Date) return new Date(date);
  61. if (typeof date === 'string' && !/Z$/i.test(date)) {
  62. var d = date.match(C.REGEX_PARSE);
  63. if (d) {
  64. var m = d[2] - 1 || 0;
  65. var ms = (d[7] || '0').substring(0, 3);
  66. if (utc) {
  67. return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
  68. }
  69. return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
  70. }
  71. }
  72. return new Date(date); // everything else
  73. };
  74. var Dayjs = /*#__PURE__*/function () {
  75. function Dayjs(cfg) {
  76. this.$L = parseLocale(cfg.locale, null, true);
  77. this.parse(cfg); // for plugin
  78. }
  79. var _proto = Dayjs.prototype;
  80. _proto.parse = function parse(cfg) {
  81. this.$d = parseDate(cfg);
  82. this.$x = cfg.x || {};
  83. this.init();
  84. };
  85. _proto.init = function init() {
  86. var $d = this.$d;
  87. this.$y = $d.getFullYear();
  88. this.$M = $d.getMonth();
  89. this.$D = $d.getDate();
  90. this.$W = $d.getDay();
  91. this.$H = $d.getHours();
  92. this.$m = $d.getMinutes();
  93. this.$s = $d.getSeconds();
  94. this.$ms = $d.getMilliseconds();
  95. } // eslint-disable-next-line class-methods-use-this
  96. ;
  97. _proto.$utils = function $utils() {
  98. return Utils;
  99. };
  100. _proto.isValid = function isValid() {
  101. return !(this.$d.toString() === C.INVALID_DATE_STRING);
  102. };
  103. _proto.isSame = function isSame(that, units) {
  104. var other = dayjs(that);
  105. return this.startOf(units) <= other && other <= this.endOf(units);
  106. };
  107. _proto.isAfter = function isAfter(that, units) {
  108. return dayjs(that) < this.startOf(units);
  109. };
  110. _proto.isBefore = function isBefore(that, units) {
  111. return this.endOf(units) < dayjs(that);
  112. };
  113. _proto.$g = function $g(input, get, set) {
  114. if (Utils.u(input)) return this[get];
  115. return this.set(set, input);
  116. };
  117. _proto.unix = function unix() {
  118. return Math.floor(this.valueOf() / 1000);
  119. };
  120. _proto.valueOf = function valueOf() {
  121. // timezone(hour) * 60 * 60 * 1000 => ms
  122. return this.$d.getTime();
  123. };
  124. _proto.startOf = function startOf(units, _startOf) {
  125. var _this = this;
  126. // startOf -> endOf
  127. var isStartOf = !Utils.u(_startOf) ? _startOf : true;
  128. var unit = Utils.p(units);
  129. var instanceFactory = function instanceFactory(d, m) {
  130. var ins = Utils.w(_this.$u ? Date.UTC(_this.$y, m, d) : new Date(_this.$y, m, d), _this);
  131. return isStartOf ? ins : ins.endOf(C.D);
  132. };
  133. var instanceFactorySet = function instanceFactorySet(method, slice) {
  134. var argumentStart = [0, 0, 0, 0];
  135. var argumentEnd = [23, 59, 59, 999];
  136. return Utils.w(_this.toDate()[method].apply( // eslint-disable-line prefer-spread
  137. _this.toDate('s'), (isStartOf ? argumentStart : argumentEnd).slice(slice)), _this);
  138. };
  139. var $W = this.$W,
  140. $M = this.$M,
  141. $D = this.$D;
  142. var utcPad = "set" + (this.$u ? 'UTC' : '');
  143. switch (unit) {
  144. case C.Y:
  145. return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11);
  146. case C.M:
  147. return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1);
  148. case C.W:
  149. {
  150. var weekStart = this.$locale().weekStart || 0;
  151. var gap = ($W < weekStart ? $W + 7 : $W) - weekStart;
  152. return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M);
  153. }
  154. case C.D:
  155. case C.DATE:
  156. return instanceFactorySet(utcPad + "Hours", 0);
  157. case C.H:
  158. return instanceFactorySet(utcPad + "Minutes", 1);
  159. case C.MIN:
  160. return instanceFactorySet(utcPad + "Seconds", 2);
  161. case C.S:
  162. return instanceFactorySet(utcPad + "Milliseconds", 3);
  163. default:
  164. return this.clone();
  165. }
  166. };
  167. _proto.endOf = function endOf(arg) {
  168. return this.startOf(arg, false);
  169. };
  170. _proto.$set = function $set(units, _int) {
  171. var _C$D$C$DATE$C$M$C$Y$C;
  172. // private set
  173. var unit = Utils.p(units);
  174. var utcPad = "set" + (this.$u ? 'UTC' : '');
  175. var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[C.D] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.DATE] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.M] = utcPad + "Month", _C$D$C$DATE$C$M$C$Y$C[C.Y] = utcPad + "FullYear", _C$D$C$DATE$C$M$C$Y$C[C.H] = utcPad + "Hours", _C$D$C$DATE$C$M$C$Y$C[C.MIN] = utcPad + "Minutes", _C$D$C$DATE$C$M$C$Y$C[C.S] = utcPad + "Seconds", _C$D$C$DATE$C$M$C$Y$C[C.MS] = utcPad + "Milliseconds", _C$D$C$DATE$C$M$C$Y$C)[unit];
  176. var arg = unit === C.D ? this.$D + (_int - this.$W) : _int;
  177. if (unit === C.M || unit === C.Y) {
  178. // clone is for badMutable plugin
  179. var date = this.clone().set(C.DATE, 1);
  180. date.$d[name](arg);
  181. date.init();
  182. this.$d = date.set(C.DATE, Math.min(this.$D, date.daysInMonth())).$d;
  183. } else if (name) this.$d[name](arg);
  184. this.init();
  185. return this;
  186. };
  187. _proto.set = function set(string, _int2) {
  188. return this.clone().$set(string, _int2);
  189. };
  190. _proto.get = function get(unit) {
  191. return this[Utils.p(unit)]();
  192. };
  193. _proto.add = function add(number, units) {
  194. var _this2 = this,
  195. _C$MIN$C$H$C$S$unit;
  196. number = Number(number); // eslint-disable-line no-param-reassign
  197. var unit = Utils.p(units);
  198. var instanceFactorySet = function instanceFactorySet(n) {
  199. var d = dayjs(_this2);
  200. return Utils.w(d.date(d.date() + Math.round(n * number)), _this2);
  201. };
  202. if (unit === C.M) {
  203. return this.set(C.M, this.$M + number);
  204. }
  205. if (unit === C.Y) {
  206. return this.set(C.Y, this.$y + number);
  207. }
  208. if (unit === C.D) {
  209. return instanceFactorySet(1);
  210. }
  211. if (unit === C.W) {
  212. return instanceFactorySet(7);
  213. }
  214. var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1; // ms
  215. var nextTimeStamp = this.$d.getTime() + number * step;
  216. return Utils.w(nextTimeStamp, this);
  217. };
  218. _proto.subtract = function subtract(number, string) {
  219. return this.add(number * -1, string);
  220. };
  221. _proto.format = function format(formatStr) {
  222. var _this3 = this;
  223. var locale = this.$locale();
  224. if (!this.isValid()) return locale.invalidDate || C.INVALID_DATE_STRING;
  225. var str = formatStr || C.FORMAT_DEFAULT;
  226. var zoneStr = Utils.z(this);
  227. var $H = this.$H,
  228. $m = this.$m,
  229. $M = this.$M;
  230. var weekdays = locale.weekdays,
  231. months = locale.months,
  232. meridiem = locale.meridiem;
  233. var getShort = function getShort(arr, index, full, length) {
  234. return arr && (arr[index] || arr(_this3, str)) || full[index].slice(0, length);
  235. };
  236. var get$H = function get$H(num) {
  237. return Utils.s($H % 12 || 12, num, '0');
  238. };
  239. var meridiemFunc = meridiem || function (hour, minute, isLowercase) {
  240. var m = hour < 12 ? 'AM' : 'PM';
  241. return isLowercase ? m.toLowerCase() : m;
  242. };
  243. var matches = {
  244. YY: String(this.$y).slice(-2),
  245. YYYY: this.$y,
  246. M: $M + 1,
  247. MM: Utils.s($M + 1, 2, '0'),
  248. MMM: getShort(locale.monthsShort, $M, months, 3),
  249. MMMM: getShort(months, $M),
  250. D: this.$D,
  251. DD: Utils.s(this.$D, 2, '0'),
  252. d: String(this.$W),
  253. dd: getShort(locale.weekdaysMin, this.$W, weekdays, 2),
  254. ddd: getShort(locale.weekdaysShort, this.$W, weekdays, 3),
  255. dddd: weekdays[this.$W],
  256. H: String($H),
  257. HH: Utils.s($H, 2, '0'),
  258. h: get$H(1),
  259. hh: get$H(2),
  260. a: meridiemFunc($H, $m, true),
  261. A: meridiemFunc($H, $m, false),
  262. m: String($m),
  263. mm: Utils.s($m, 2, '0'),
  264. s: String(this.$s),
  265. ss: Utils.s(this.$s, 2, '0'),
  266. SSS: Utils.s(this.$ms, 3, '0'),
  267. Z: zoneStr // 'ZZ' logic below
  268. };
  269. return str.replace(C.REGEX_FORMAT, function (match, $1) {
  270. return $1 || matches[match] || zoneStr.replace(':', '');
  271. }); // 'ZZ'
  272. };
  273. _proto.utcOffset = function utcOffset() {
  274. // Because a bug at FF24, we're rounding the timezone offset around 15 minutes
  275. // https://github.com/moment/moment/pull/1871
  276. return -Math.round(this.$d.getTimezoneOffset() / 15) * 15;
  277. };
  278. _proto.diff = function diff(input, units, _float) {
  279. var _C$Y$C$M$C$Q$C$W$C$D$;
  280. var unit = Utils.p(units);
  281. var that = dayjs(input);
  282. var zoneDelta = (that.utcOffset() - this.utcOffset()) * C.MILLISECONDS_A_MINUTE;
  283. var diff = this - that;
  284. var result = Utils.m(this, that);
  285. result = (_C$Y$C$M$C$Q$C$W$C$D$ = {}, _C$Y$C$M$C$Q$C$W$C$D$[C.Y] = result / 12, _C$Y$C$M$C$Q$C$W$C$D$[C.M] = result, _C$Y$C$M$C$Q$C$W$C$D$[C.Q] = result / 3, _C$Y$C$M$C$Q$C$W$C$D$[C.W] = (diff - zoneDelta) / C.MILLISECONDS_A_WEEK, _C$Y$C$M$C$Q$C$W$C$D$[C.D] = (diff - zoneDelta) / C.MILLISECONDS_A_DAY, _C$Y$C$M$C$Q$C$W$C$D$[C.H] = diff / C.MILLISECONDS_A_HOUR, _C$Y$C$M$C$Q$C$W$C$D$[C.MIN] = diff / C.MILLISECONDS_A_MINUTE, _C$Y$C$M$C$Q$C$W$C$D$[C.S] = diff / C.MILLISECONDS_A_SECOND, _C$Y$C$M$C$Q$C$W$C$D$)[unit] || diff; // milliseconds
  286. return _float ? result : Utils.a(result);
  287. };
  288. _proto.daysInMonth = function daysInMonth() {
  289. return this.endOf(C.M).$D;
  290. };
  291. _proto.$locale = function $locale() {
  292. // get locale object
  293. return Ls[this.$L];
  294. };
  295. _proto.locale = function locale(preset, object) {
  296. if (!preset) return this.$L;
  297. var that = this.clone();
  298. var nextLocaleName = parseLocale(preset, object, true);
  299. if (nextLocaleName) that.$L = nextLocaleName;
  300. return that;
  301. };
  302. _proto.clone = function clone() {
  303. return Utils.w(this.$d, this);
  304. };
  305. _proto.toDate = function toDate() {
  306. return new Date(this.valueOf());
  307. };
  308. _proto.toJSON = function toJSON() {
  309. return this.isValid() ? this.toISOString() : null;
  310. };
  311. _proto.toISOString = function toISOString() {
  312. // ie 8 return
  313. // new Dayjs(this.valueOf() + this.$d.getTimezoneOffset() * 60000)
  314. // .format('YYYY-MM-DDTHH:mm:ss.SSS[Z]')
  315. return this.$d.toISOString();
  316. };
  317. _proto.toString = function toString() {
  318. return this.$d.toUTCString();
  319. };
  320. return Dayjs;
  321. }();
  322. var proto = Dayjs.prototype;
  323. dayjs.prototype = proto;
  324. [['$ms', C.MS], ['$s', C.S], ['$m', C.MIN], ['$H', C.H], ['$W', C.D], ['$M', C.M], ['$y', C.Y], ['$D', C.DATE]].forEach(function (g) {
  325. proto[g[1]] = function (input) {
  326. return this.$g(input, g[0], g[1]);
  327. };
  328. });
  329. dayjs.extend = function (plugin, option) {
  330. if (!plugin.$i) {
  331. // install plugin only once
  332. plugin(option, Dayjs, dayjs);
  333. plugin.$i = true;
  334. }
  335. return dayjs;
  336. };
  337. dayjs.locale = parseLocale;
  338. dayjs.isDayjs = isDayjs;
  339. dayjs.unix = function (timestamp) {
  340. return dayjs(timestamp * 1e3);
  341. };
  342. dayjs.en = Ls[L];
  343. dayjs.Ls = Ls;
  344. dayjs.p = {};
  345. export default dayjs;