view_helpers.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. QUnit.test("time_duration_hh_mm", assert => {
  2. let func = App.ViewHelpers.time_duration_hh_mm
  3. assert.equal(func(1), '00:01')
  4. assert.equal(func(61), '01:01')
  5. assert.equal(func(3600), '60:00')
  6. assert.equal(func(7200), '120:00')
  7. })
  8. QUnit.test("time_duration", assert => {
  9. let func = App.ViewHelpers.time_duration
  10. assert.equal(func(1), '00:01')
  11. assert.equal(func(61), '01:01')
  12. assert.equal(func(3600), '1:00:00')
  13. assert.equal(func(7200), '2:00:00')
  14. assert.equal(func(36000), '10:00:00')
  15. assert.equal(func(360101), '100:01:41')
  16. })
  17. QUnit.test('relative_time', assert => {
  18. let func = App.ViewHelpers.relative_time
  19. clock = sinon.useFakeTimers({ now: new Date('2022-11-15T10:00:00.000Z') })
  20. assert.equal(func(1, 'minute'), '2022-11-15T10:01:00.000Z')
  21. assert.equal(func(5, 'hour'), '2022-11-15T15:00:00.000Z')
  22. assert.equal(func(3, 'day'), '2022-11-18T10:00:00.000Z')
  23. assert.equal(func(4, 'week'), '2022-12-13T10:00:00.000Z')
  24. assert.equal(func(8, 'month'), '2023-07-15T09:00:00.000Z')
  25. assert.equal(func(2, 'year'), '2024-11-15T10:00:00.000Z')
  26. clock.restore()
  27. })
  28. QUnit.test('relative_time - setMonth() sanity check', assert => {
  29. let func = App.ViewHelpers.relative_time
  30. clock = sinon.useFakeTimers({ now: new Date('2023-01-01T12:00:00.000Z') })
  31. assert.equal(func(1, 'month'), '2023-02-01T12:00:00.000Z', '1st of the month - 1 month')
  32. assert.equal(func(2, 'month'), '2023-03-01T12:00:00.000Z', '1st of the month - 2 months')
  33. assert.equal(func(3, 'month'), '2023-04-01T11:00:00.000Z', '1st of the month - 3 months')
  34. assert.equal(func(4, 'month'), '2023-05-01T11:00:00.000Z', '1st of the month - 4 months')
  35. assert.equal(func(5, 'month'), '2023-06-01T11:00:00.000Z', '1st of the month - 5 months')
  36. assert.equal(func(6, 'month'), '2023-07-01T11:00:00.000Z', '1st of the month - 6 months')
  37. assert.equal(func(7, 'month'), '2023-08-01T11:00:00.000Z', '1st of the month - 7 months')
  38. assert.equal(func(8, 'month'), '2023-09-01T11:00:00.000Z', '1st of the month - 8 months')
  39. assert.equal(func(9, 'month'), '2023-10-01T11:00:00.000Z', '1st of the month - 9 months')
  40. assert.equal(func(10, 'month'), '2023-11-01T12:00:00.000Z', '1st of the month - 10 months')
  41. assert.equal(func(11, 'month'), '2023-12-01T12:00:00.000Z', '1st of the month - 11 months')
  42. assert.equal(func(12, 'month'), '2024-01-01T12:00:00.000Z', '1st of the month - 12 months')
  43. clock = sinon.useFakeTimers({ now: new Date('2023-01-28T12:00:00.000Z') })
  44. assert.equal(func(1, 'month'), '2023-02-28T12:00:00.000Z', '28th of the month - 1 month')
  45. assert.equal(func(2, 'month'), '2023-03-28T11:00:00.000Z', '28th of the month - 2 months')
  46. assert.equal(func(3, 'month'), '2023-04-28T11:00:00.000Z', '28th of the month - 3 months')
  47. assert.equal(func(4, 'month'), '2023-05-28T11:00:00.000Z', '28th of the month - 4 months')
  48. assert.equal(func(5, 'month'), '2023-06-28T11:00:00.000Z', '28th of the month - 5 months')
  49. assert.equal(func(6, 'month'), '2023-07-28T11:00:00.000Z', '28th of the month - 6 months')
  50. assert.equal(func(7, 'month'), '2023-08-28T11:00:00.000Z', '28th of the month - 7 months')
  51. assert.equal(func(8, 'month'), '2023-09-28T11:00:00.000Z', '28th of the month - 8 months')
  52. assert.equal(func(9, 'month'), '2023-10-28T11:00:00.000Z', '28th of the month - 9 months')
  53. assert.equal(func(10, 'month'), '2023-11-28T12:00:00.000Z', '28th of the month - 10 months')
  54. assert.equal(func(11, 'month'), '2023-12-28T12:00:00.000Z', '28th of the month - 11 months')
  55. assert.equal(func(12, 'month'), '2024-01-28T12:00:00.000Z', '28th of the month - 12 months')
  56. clock = sinon.useFakeTimers({ now: new Date('2023-01-29T12:00:00.000Z') })
  57. assert.equal(func(1, 'month'), '2023-03-01T12:00:00.000Z', '29th of the month - 1 month')
  58. assert.equal(func(2, 'month'), '2023-03-29T11:00:00.000Z', '29th of the month - 2 months')
  59. assert.equal(func(3, 'month'), '2023-04-29T11:00:00.000Z', '29th of the month - 3 months')
  60. assert.equal(func(4, 'month'), '2023-05-29T11:00:00.000Z', '29th of the month - 4 months')
  61. assert.equal(func(5, 'month'), '2023-06-29T11:00:00.000Z', '29th of the month - 5 months')
  62. assert.equal(func(6, 'month'), '2023-07-29T11:00:00.000Z', '29th of the month - 6 months')
  63. assert.equal(func(7, 'month'), '2023-08-29T11:00:00.000Z', '29th of the month - 7 months')
  64. assert.equal(func(8, 'month'), '2023-09-29T11:00:00.000Z', '29th of the month - 8 months')
  65. assert.equal(func(9, 'month'), '2023-10-29T12:00:00.000Z', '29th of the month - 9 months')
  66. assert.equal(func(10, 'month'), '2023-11-29T12:00:00.000Z', '29th of the month - 10 months')
  67. assert.equal(func(11, 'month'), '2023-12-29T12:00:00.000Z', '29th of the month - 11 months')
  68. assert.equal(func(12, 'month'), '2024-01-29T12:00:00.000Z', '29th of the month - 12 months')
  69. clock = sinon.useFakeTimers({ now: new Date('2023-01-30T12:00:00.000Z') })
  70. assert.equal(func(1, 'month'), '2023-03-02T12:00:00.000Z', '30th of the month - 1 month')
  71. assert.equal(func(2, 'month'), '2023-03-30T11:00:00.000Z', '30th of the month - 2 months')
  72. assert.equal(func(3, 'month'), '2023-04-30T11:00:00.000Z', '30th of the month - 3 months')
  73. assert.equal(func(4, 'month'), '2023-05-30T11:00:00.000Z', '30th of the month - 4 months')
  74. assert.equal(func(5, 'month'), '2023-06-30T11:00:00.000Z', '30th of the month - 5 months')
  75. assert.equal(func(6, 'month'), '2023-07-30T11:00:00.000Z', '30th of the month - 6 months')
  76. assert.equal(func(7, 'month'), '2023-08-30T11:00:00.000Z', '30th of the month - 7 months')
  77. assert.equal(func(8, 'month'), '2023-09-30T11:00:00.000Z', '30th of the month - 8 months')
  78. assert.equal(func(9, 'month'), '2023-10-30T12:00:00.000Z', '30th of the month - 9 months')
  79. assert.equal(func(10, 'month'), '2023-11-30T12:00:00.000Z', '30th of the month - 10 months')
  80. assert.equal(func(11, 'month'), '2023-12-30T12:00:00.000Z', '30th of the month - 11 months')
  81. assert.equal(func(12, 'month'), '2024-01-30T12:00:00.000Z', '30th of the month - 12 months')
  82. clock = sinon.useFakeTimers({ now: new Date('2023-01-31T12:00:00.000Z') })
  83. assert.equal(func(1, 'month'), '2023-03-03T12:00:00.000Z', '31st of the month - 1 month')
  84. assert.equal(func(2, 'month'), '2023-03-31T11:00:00.000Z', '31st of the month - 2 months')
  85. assert.equal(func(3, 'month'), '2023-05-01T11:00:00.000Z', '31st of the month - 3 months')
  86. assert.equal(func(4, 'month'), '2023-05-31T11:00:00.000Z', '31st of the month - 4 months')
  87. assert.equal(func(5, 'month'), '2023-07-01T11:00:00.000Z', '31st of the month - 5 months')
  88. assert.equal(func(6, 'month'), '2023-07-31T11:00:00.000Z', '31st of the month - 6 months')
  89. assert.equal(func(7, 'month'), '2023-08-31T11:00:00.000Z', '31st of the month - 7 months')
  90. assert.equal(func(8, 'month'), '2023-10-01T11:00:00.000Z', '31st of the month - 8 months')
  91. assert.equal(func(9, 'month'), '2023-10-31T12:00:00.000Z', '31st of the month - 9 months')
  92. assert.equal(func(10, 'month'), '2023-12-01T12:00:00.000Z', '31st of the month - 10 months')
  93. assert.equal(func(11, 'month'), '2023-12-31T12:00:00.000Z', '31st of the month - 11 months')
  94. assert.equal(func(12, 'month'), '2024-01-31T12:00:00.000Z', '31st of the month - 12 months')
  95. clock.restore()
  96. })