c1a9c520a9784dec520c8a7864f0e5b36dcae92f15c8bd5b09156a247aff399ad275574a8f12ad0a661cb12eb2f72cce9f4844acd6090b788e8ee45049df2d 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. export function createDate(y, m, d, h, M, s, ms) {
  2. // can't just apply() to create a date:
  3. // https://stackoverflow.com/q/181348
  4. var date;
  5. // the date constructor remaps years 0-99 to 1900-1999
  6. if (y < 100 && y >= 0) {
  7. // preserve leap years using a full 400 year cycle, then reset
  8. date = new Date(y + 400, m, d, h, M, s, ms);
  9. if (isFinite(date.getFullYear())) {
  10. date.setFullYear(y);
  11. }
  12. } else {
  13. date = new Date(y, m, d, h, M, s, ms);
  14. }
  15. return date;
  16. }
  17. export function createUTCDate(y) {
  18. var date, args;
  19. // the Date.UTC function remaps years 0-99 to 1900-1999
  20. if (y < 100 && y >= 0) {
  21. args = Array.prototype.slice.call(arguments);
  22. // preserve leap years using a full 400 year cycle, then reset
  23. args[0] = y + 400;
  24. date = new Date(Date.UTC.apply(null, args));
  25. if (isFinite(date.getUTCFullYear())) {
  26. date.setUTCFullYear(y);
  27. }
  28. } else {
  29. date = new Date(Date.UTC.apply(null, arguments));
  30. }
  31. return date;
  32. }