formatRange.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. describe('formatRange', function() {
  2. it('doesn\'t do any splitting when dates have different years', function() {
  3. var s = $.fullCalendar.formatRange('2014-01-01', '2015-01-01', 'MMMM Do YYYY');
  4. expect(s).toEqual('January 1st 2014 - January 1st 2015');
  5. });
  6. it('splits correctly on day when dates have same month', function() {
  7. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'MMMM Do YYYY');
  8. expect(s).toEqual('January 1st - 5th 2014');
  9. });
  10. it('splits correctly on day when dates have same month and smaller unit in front', function() {
  11. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'dddd MMMM Do YYYY');
  12. expect(s).toEqual('Wednesday January 1st - Sunday January 5th 2014');
  13. });
  14. it('splits correctly on the time when dates have the same day', function() {
  15. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T08:00:00', 'MMMM Do YYYY h:mma');
  16. expect(s).toEqual('January 1st 2014 6:00am - 8:00am');
  17. });
  18. it('splits correctly on the time when dates have the same day and hour but different am/pm', function() {
  19. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T18:00:00', 'MMMM Do YYYY h:mma');
  20. expect(s).toEqual('January 1st 2014 6:00am - 6:00pm');
  21. });
  22. it('splits correctly on the time when the dates have the same hour', function() {
  23. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:30:00', 'MMMM Do YYYY h:mma');
  24. expect(s).toEqual('January 1st 2014 6:00am - 6:30am');
  25. });
  26. it('doesn\'t split a period (German)', function() {
  27. var date1 = moment('2014-08-11').locale('de');
  28. var date2 = moment('2014-08-17').locale('de');
  29. var s = $.fullCalendar.formatRange(date1, date2, 'll');
  30. expect(s).toEqual('11. - 17. Aug. 2014');
  31. });
  32. it('doesn\'t split a period (Czech)', function() {
  33. var date1 = moment('2017-01-15').locale('cs');
  34. var date2 = moment('2017-01-21').locale('cs');
  35. var s = $.fullCalendar.formatRange(date1, date2, 'D. M. YYYY');
  36. expect(s).toEqual('15. - 21. 1. 2017');
  37. });
  38. it('uses non-standalone version of month (Russian)', function() {
  39. var date1 = moment('2015-01-02').locale('ru');
  40. var date2 = moment('2015-01-08').locale('ru');
  41. var s = $.fullCalendar.formatRange(date1, date2, 'DD MMMM YYYY');
  42. expect(s).toEqual('02 - 08 января 2015');
  43. });
  44. it('outputs the single date when the dates have the same day and time', function() {
  45. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:00:00', 'MMMM Do YYYY h:mma');
  46. expect(s).toEqual('January 1st 2014 6:00am');
  47. });
  48. it('outputs the single date when the dates have the same day and the format string is vague', function() {
  49. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-01', 'MMMM Do YYYY');
  50. expect(s).toEqual('January 1st 2014');
  51. });
  52. it('outputs the single week number when dates have the same week and format string is week', function() {
  53. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-01', 'W');
  54. expect(s).toEqual('1');
  55. });
  56. it('uses a custom separator', function() {
  57. var s = $.fullCalendar.formatRange(
  58. '2014-01-01T06:00:00',
  59. '2014-01-01T06:30:00',
  60. 'MMMM Do YYYY h:mma',
  61. '<...>'
  62. );
  63. expect(s).toEqual('January 1st 2014 6:00am<...>6:30am');
  64. });
  65. describe('when called with isRTL', function() {
  66. it('doesn\'t do any splitting when dates have different years', function() {
  67. var s = $.fullCalendar.formatRange('2014-01-01', '2015-01-01', 'MMMM Do YYYY', null, true);
  68. expect(s).toEqual('January 1st 2015 - January 1st 2014');
  69. });
  70. it('splits correctly on day when dates have same month', function() {
  71. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'MMMM Do YYYY', null, true);
  72. expect(s).toEqual('January 5th - 1st 2014');
  73. });
  74. it('splits correctly on day when dates have same month and smaller unit in front', function() {
  75. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-05', 'dddd MMMM Do YYYY', null, true);
  76. expect(s).toEqual('Sunday January 5th - Wednesday January 1st 2014');
  77. });
  78. it('splits correctly on the time when dates have the same day', function() {
  79. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T08:00:00', 'MMMM Do YYYY h:mma', null, true);
  80. expect(s).toEqual('January 1st 2014 8:00am - 6:00am');
  81. });
  82. it('splits correctly on the time when dates have the same day and hour but different am/pm', function() {
  83. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T18:00:00', 'MMMM Do YYYY h:mma', null, true);
  84. expect(s).toEqual('January 1st 2014 6:00pm - 6:00am');
  85. });
  86. it('splits correctly on the time when the dates have the same hour', function() {
  87. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:30:00', 'MMMM Do YYYY h:mma', null, true);
  88. expect(s).toEqual('January 1st 2014 6:30am - 6:00am');
  89. });
  90. it('outputs the single date when the dates have the same day and time', function() {
  91. var s = $.fullCalendar.formatRange('2014-01-01T06:00:00', '2014-01-01T06:00:00', 'MMMM Do YYYY h:mma', null, true);
  92. expect(s).toEqual('January 1st 2014 6:00am');
  93. });
  94. it('outputs the single date when the dates have the same day and the format string is vague', function() {
  95. var s = $.fullCalendar.formatRange('2014-01-01', '2014-01-01', 'MMMM Do YYYY', null, true);
  96. expect(s).toEqual('January 1st 2014');
  97. });
  98. it('uses a custom separator', function() {
  99. var s = $.fullCalendar.formatRange(
  100. '2014-01-01T06:00:00',
  101. '2014-01-01T06:30:00',
  102. 'MMMM Do YYYY h:mma',
  103. '<...>',
  104. true
  105. );
  106. expect(s).toEqual('January 1st 2014 6:30am<...>6:00am');
  107. });
  108. });
  109. describe('when calendar has isRTL', function() {
  110. it('splits correctly on day when dates have same month', function() {
  111. affix('#cal');
  112. $('#cal').fullCalendar({
  113. defaultView: 'basicWeek',
  114. defaultDate: '2014-05-20',
  115. isRTL: true,
  116. titleFormat: 'MMMM Do YYYY',
  117. titleRangeSeparator: ' - '
  118. });
  119. expect($('.fc-toolbar h2')).toHaveText('May 24th - 18th 2014');
  120. });
  121. });
  122. describe('when calendar has a customized locale', function() {
  123. it('uses locale and splits correctly on day when dates have same month', function() {
  124. affix('#cal');
  125. $('#cal').fullCalendar({
  126. defaultView: 'basicWeek',
  127. defaultDate: '2014-05-20',
  128. locale: 'fr',
  129. titleFormat: 'dddd MMMM D YYYY',
  130. titleRangeSeparator: ' - '
  131. });
  132. expect($('.fc-toolbar h2')).toHaveText('lundi mai 19 - dimanche mai 25 2014');
  133. });
  134. });
  135. it('splits correctly on day when dates have same month, when given real moments', function() {
  136. var s = $.fullCalendar.formatRange(
  137. moment.utc('2014-01-01'),
  138. moment.utc('2015-01-01'),
  139. 'MMMM Do YYYY'
  140. );
  141. expect(s).toEqual('January 1st 2014 - January 1st 2015');
  142. });
  143. });