timeOptions2.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import moment from "moment"
  2. export default {
  3. shortcuts: [
  4. {
  5. text: "今天",
  6. value() {
  7. const end = new Date();
  8. const start = new Date();
  9. start.setTime(
  10. new Date(
  11. new Date().getFullYear(),
  12. new Date().getMonth(),
  13. new Date().getDate()
  14. )
  15. );
  16. return [start, end];
  17. },
  18. },
  19. {
  20. text: "昨天",
  21. value() {
  22. const end = new Date();
  23. const start = new Date();
  24. start.setTime(
  25. start.setTime(
  26. new Date(
  27. new Date().getFullYear(),
  28. new Date().getMonth(),
  29. new Date().getDate() - 1
  30. )
  31. )
  32. );
  33. end.setTime(
  34. end.setTime(
  35. new Date(
  36. new Date().getFullYear(),
  37. new Date().getMonth(),
  38. new Date().getDate() - 1
  39. )
  40. )
  41. );
  42. return [start, end];
  43. },
  44. },
  45. {
  46. text: "最近7天",
  47. value() {
  48. const end = new Date();
  49. const start = new Date();
  50. start.setTime(
  51. start.setTime(
  52. new Date(
  53. new Date().getFullYear(),
  54. new Date().getMonth(),
  55. new Date().getDate() - 6
  56. )
  57. )
  58. );
  59. return [start, end];
  60. },
  61. },
  62. {
  63. text: "最近30天",
  64. value() {
  65. const end = new Date();
  66. const start = new Date();
  67. start.setTime(
  68. start.setTime(
  69. new Date(
  70. new Date().getFullYear(),
  71. new Date().getMonth(),
  72. new Date().getDate() - 29
  73. )
  74. )
  75. );
  76. return [start, end];
  77. },
  78. },
  79. {
  80. text: "上月",
  81. value() {
  82. const end = new Date();
  83. const start = new Date();
  84. const day = new Date(start.getFullYear(), start.getMonth(), 0).getDate();
  85. start.setTime(
  86. start.setTime(
  87. new Date(new Date().getFullYear(), new Date().getMonth()-1, 1)
  88. )
  89. );
  90. end.setTime(
  91. end.setTime(
  92. new Date(new Date().getFullYear(), new Date().getMonth()-1, day)
  93. )
  94. );
  95. return [start, end];
  96. },
  97. },
  98. {
  99. text: "本月",
  100. value() {
  101. const end = new Date();
  102. const start = new Date();
  103. start.setTime(
  104. start.setTime(
  105. new Date(new Date().getFullYear(), new Date().getMonth(), 1)
  106. )
  107. );
  108. return [start, end];
  109. },
  110. },
  111. {
  112. text: "本季度",
  113. value() {
  114. const start = moment(moment().quarter(moment().quarter()).startOf('quarter').valueOf()).format('YYYY-MM-DD');
  115. const end = moment(moment().quarter(moment().quarter()).endOf('quarter').valueOf()).format('YYYY-MM-DD');
  116. return [start, end];
  117. },
  118. },
  119. {
  120. text: "本年",
  121. value() {
  122. const end = new Date();
  123. const start = new Date();
  124. start.setTime(start.setTime(new Date(new Date().getFullYear(), 0, 1)));
  125. return [start, end];
  126. },
  127. },
  128. ],
  129. };
  130. // var now = new Date(); //当前日期
  131. // var nowMonth = now.getMonth(); //当前月
  132. // function getQuarterStartMonth(){
  133. // var quarterStartMonth = 0;
  134. // if(nowMonth<3){
  135. // quarterStartMonth = 0;
  136. // }
  137. // if(2<nowMonth && nowMonth<6){
  138. // quarterStartMonth = 3;
  139. // }
  140. // if(5<nowMonth && nowMonth<9){
  141. // quarterStartMonth = 6;
  142. // }
  143. // if(nowMonth>8){
  144. // quarterStartMonth = 9;
  145. // }
  146. // return quarterStartMonth;
  147. // }
  148. // function getQuarterStartDate(){
  149. // var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
  150. // return formatDate(quarterStartDate);
  151. // }
  152. // //或的本季度的停止日期
  153. // function getQuarterEndDate(){
  154. // var quarterEndMonth = getQuarterStartMonth() + 2;
  155. // var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
  156. // return formatDate(quarterStartDate);
  157. // }