b55f43543e825a2e109d2d5fcf4ec03fdc2b255ad06d0600b34c6055fd6cf0151f3ad5fa4d7ed76b05fad23639ed604b329717ac0e532dae014eb6fc601bed 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import { formatMoment } from '../format/format';
  2. import { hooks } from '../utils/hooks';
  3. import isFunction from '../utils/is-function';
  4. hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  5. hooks.defaultFormatUtc = 'YYYY-MM-DDTHH:mm:ss[Z]';
  6. export function toString () {
  7. return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');
  8. }
  9. export function toISOString () {
  10. var m = this.clone().utc();
  11. if (0 < m.year() && m.year() <= 9999) {
  12. if (isFunction(Date.prototype.toISOString)) {
  13. // native implementation is ~50x faster, use it when we can
  14. return this.toDate().toISOString();
  15. } else {
  16. return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  17. }
  18. } else {
  19. return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');
  20. }
  21. }
  22. export function format (inputString) {
  23. if (!inputString) {
  24. inputString = this.isUtc() ? hooks.defaultFormatUtc : hooks.defaultFormat;
  25. }
  26. var output = formatMoment(this, inputString);
  27. return this.localeData().postformat(output);
  28. }