d3Time.test.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import {
  20. utcUtils,
  21. localTimeUtils,
  22. } from '../../../src/time-format/utils/d3Time';
  23. describe('utils', () => {
  24. describe('utcUtils', () => {
  25. it('has isNotFirstDayOfWeekStartOnSunday', () => {
  26. const date = new Date(Date.UTC(2018, 10, 19));
  27. expect(utcUtils.isNotFirstDayOfWeekStartOnSunday(date)).toBeTruthy();
  28. const date2 = new Date(Date.UTC(2018, 10, 18));
  29. expect(utcUtils.isNotFirstDayOfWeekStartOnSunday(date2)).toBeFalsy();
  30. });
  31. it('has isNotFirstDayOfWeekStartOnMonday', () => {
  32. const date = new Date(Date.UTC(2018, 10, 20));
  33. expect(utcUtils.isNotFirstDayOfWeekStartOnMonday(date)).toBeTruthy();
  34. const date2 = new Date(Date.UTC(2018, 10, 19));
  35. expect(utcUtils.isNotFirstDayOfWeekStartOnMonday(date2)).toBeFalsy();
  36. });
  37. it('has isNotFirstDayOfWeekStartOnTuesday', () => {
  38. const date = new Date(Date.UTC(2018, 10, 21));
  39. expect(utcUtils.isNotFirstDayOfWeekStartOnTuesday(date)).toBeTruthy();
  40. const date2 = new Date(Date.UTC(2018, 10, 20));
  41. expect(utcUtils.isNotFirstDayOfWeekStartOnTuesday(date2)).toBeFalsy();
  42. });
  43. it('has isNotFirstDayOfWeekStartOnWednesday', () => {
  44. const date = new Date(Date.UTC(2018, 10, 22));
  45. expect(utcUtils.isNotFirstDayOfWeekStartOnWednesday(date)).toBeTruthy();
  46. const date2 = new Date(Date.UTC(2018, 10, 21));
  47. expect(utcUtils.isNotFirstDayOfWeekStartOnWednesday(date2)).toBeFalsy();
  48. });
  49. it('has isNotFirstDayOfWeekStartOnThursday', () => {
  50. const date = new Date(Date.UTC(2018, 10, 23));
  51. expect(utcUtils.isNotFirstDayOfWeekStartOnThursday(date)).toBeTruthy();
  52. const date2 = new Date(Date.UTC(2018, 10, 22));
  53. expect(utcUtils.isNotFirstDayOfWeekStartOnThursday(date2)).toBeFalsy();
  54. });
  55. it('has isNotFirstDayOfWeekStartOnFriday', () => {
  56. const date = new Date(Date.UTC(2018, 10, 24));
  57. expect(utcUtils.isNotFirstDayOfWeekStartOnFriday(date)).toBeTruthy();
  58. const date2 = new Date(Date.UTC(2018, 10, 23));
  59. expect(utcUtils.isNotFirstDayOfWeekStartOnFriday(date2)).toBeFalsy();
  60. });
  61. it('has isNotFirstDayOfWeekStartOnSaturday', () => {
  62. const date = new Date(Date.UTC(2018, 10, 25));
  63. expect(utcUtils.isNotFirstDayOfWeekStartOnSaturday(date)).toBeTruthy();
  64. const date2 = new Date(Date.UTC(2018, 10, 24));
  65. expect(utcUtils.isNotFirstDayOfWeekStartOnSaturday(date2)).toBeFalsy();
  66. });
  67. });
  68. describe('localTimeUtils', () => {
  69. it('has isNotFirstDayOfWeekStartOnSunday', () => {
  70. const date = new Date(2018, 10, 19);
  71. expect(
  72. localTimeUtils.isNotFirstDayOfWeekStartOnSunday(date),
  73. ).toBeTruthy();
  74. const date2 = new Date(2018, 10, 18);
  75. expect(
  76. localTimeUtils.isNotFirstDayOfWeekStartOnSunday(date2),
  77. ).toBeFalsy();
  78. });
  79. it('has isNotFirstDayOfWeekStartOnMonday', () => {
  80. const date = new Date(2018, 10, 20);
  81. expect(
  82. localTimeUtils.isNotFirstDayOfWeekStartOnMonday(date),
  83. ).toBeTruthy();
  84. const date2 = new Date(2018, 10, 19);
  85. expect(
  86. localTimeUtils.isNotFirstDayOfWeekStartOnMonday(date2),
  87. ).toBeFalsy();
  88. });
  89. it('has isNotFirstDayOfWeekStartOnTuesday', () => {
  90. const date = new Date(2018, 10, 21);
  91. expect(
  92. localTimeUtils.isNotFirstDayOfWeekStartOnTuesday(date),
  93. ).toBeTruthy();
  94. const date2 = new Date(2018, 10, 20);
  95. expect(
  96. localTimeUtils.isNotFirstDayOfWeekStartOnTuesday(date2),
  97. ).toBeFalsy();
  98. });
  99. it('has isNotFirstDayOfWeekStartOnWednesday', () => {
  100. const date = new Date(2018, 10, 22);
  101. expect(
  102. localTimeUtils.isNotFirstDayOfWeekStartOnWednesday(date),
  103. ).toBeTruthy();
  104. const date2 = new Date(2018, 10, 21);
  105. expect(
  106. localTimeUtils.isNotFirstDayOfWeekStartOnWednesday(date2),
  107. ).toBeFalsy();
  108. });
  109. it('has isNotFirstDayOfWeekStartOnThursday', () => {
  110. const date = new Date(2018, 10, 23);
  111. expect(
  112. localTimeUtils.isNotFirstDayOfWeekStartOnThursday(date),
  113. ).toBeTruthy();
  114. const date2 = new Date(2018, 10, 22);
  115. expect(
  116. localTimeUtils.isNotFirstDayOfWeekStartOnThursday(date2),
  117. ).toBeFalsy();
  118. });
  119. it('has isNotFirstDayOfWeekStartOnFriday', () => {
  120. const date = new Date(2018, 10, 24);
  121. expect(
  122. localTimeUtils.isNotFirstDayOfWeekStartOnFriday(date),
  123. ).toBeTruthy();
  124. const date2 = new Date(2018, 10, 23);
  125. expect(
  126. localTimeUtils.isNotFirstDayOfWeekStartOnFriday(date2),
  127. ).toBeFalsy();
  128. });
  129. it('has isNotFirstDayOfWeekStartOnSaturday', () => {
  130. const date = new Date(2018, 10, 25);
  131. expect(
  132. localTimeUtils.isNotFirstDayOfWeekStartOnSaturday(date),
  133. ).toBeTruthy();
  134. const date2 = new Date(2018, 10, 24);
  135. expect(
  136. localTimeUtils.isNotFirstDayOfWeekStartOnSaturday(date2),
  137. ).toBeFalsy();
  138. });
  139. });
  140. });