Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Plugin template from https://day.js.org/docs/en/plugin/plugin
  2. export default (function (option, dayjsClass) {
  3. var oldParse = dayjsClass.prototype.parse;
  4. dayjsClass.prototype.parse = function (cfg) {
  5. if (typeof cfg.date === 'string') {
  6. var locale = this.$locale();
  7. cfg.date = locale && locale.preparse ? locale.preparse(cfg.date) : cfg.date;
  8. } // original parse result
  9. return oldParse.bind(this)(cfg);
  10. }; // // overriding existing API
  11. // // e.g. extend dayjs().format()
  12. var oldFormat = dayjsClass.prototype.format;
  13. dayjsClass.prototype.format = function () {
  14. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  15. args[_key] = arguments[_key];
  16. }
  17. // original format result
  18. var result = oldFormat.call.apply(oldFormat, [this].concat(args)); // return modified result
  19. var locale = this.$locale();
  20. return locale && locale.postformat ? locale.postformat(result) : result;
  21. };
  22. var oldFromTo = dayjsClass.prototype.fromToBase;
  23. if (oldFromTo) {
  24. dayjsClass.prototype.fromToBase = function (input, withoutSuffix, instance, isFrom) {
  25. var locale = this.$locale() || instance.$locale(); // original format result
  26. return oldFromTo.call(this, input, withoutSuffix, instance, isFrom, locale && locale.postformat);
  27. };
  28. }
  29. });