MonthFromTime.js 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var DayWithinYear = require('./DayWithinYear');
  3. var InLeapYear = require('./InLeapYear');
  4. // https://262.ecma-international.org/5.1/#sec-15.9.1.4
  5. module.exports = function MonthFromTime(t) {
  6. var day = DayWithinYear(t);
  7. if (0 <= day && day < 31) {
  8. return 0;
  9. }
  10. var leap = InLeapYear(t);
  11. if (31 <= day && day < (59 + leap)) {
  12. return 1;
  13. }
  14. if ((59 + leap) <= day && day < (90 + leap)) {
  15. return 2;
  16. }
  17. if ((90 + leap) <= day && day < (120 + leap)) {
  18. return 3;
  19. }
  20. if ((120 + leap) <= day && day < (151 + leap)) {
  21. return 4;
  22. }
  23. if ((151 + leap) <= day && day < (181 + leap)) {
  24. return 5;
  25. }
  26. if ((181 + leap) <= day && day < (212 + leap)) {
  27. return 6;
  28. }
  29. if ((212 + leap) <= day && day < (243 + leap)) {
  30. return 7;
  31. }
  32. if ((243 + leap) <= day && day < (273 + leap)) {
  33. return 8;
  34. }
  35. if ((273 + leap) <= day && day < (304 + leap)) {
  36. return 9;
  37. }
  38. if ((304 + leap) <= day && day < (334 + leap)) {
  39. return 10;
  40. }
  41. if ((334 + leap) <= day && day < (365 + leap)) {
  42. return 11;
  43. }
  44. };