changeCourseTime.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // 判断当前月份的总天数
  2. const thisMonthLenth = (year, month) => {
  3. let len
  4. if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
  5. len = 31
  6. } else if (month == 4 || month == 6 || month == 9 || month == 11) {
  7. len = 30
  8. } else if (month == 2) {
  9. if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) {
  10. len = 29
  11. } else {
  12. len = 28
  13. }
  14. }
  15. return len
  16. }
  17. // 获取最小的日期
  18. const startDate = res => {
  19. if (res.length > 0) {
  20. let date = res[0]
  21. for (let i in res) {
  22. date = new Date(res[i]['date'].replace(/\-/g, "/")) < new Date(date['date'].replace(/\-/g, "/")) ? res[i] : date
  23. }
  24. return date
  25. }
  26. }
  27. // 判断是否是最大的日期
  28. const isMaxDate = (date, data) => {
  29. let isSame = false
  30. let index = null
  31. if (data.length > 0) {
  32. for (let i in data) {
  33. if (new Date(date.replace(/\-/g, "/")).getTime() >= new Date(data[i]['date'].replace(/\-/g, "/")).getTime()) {
  34. isSame = true
  35. index = i
  36. break
  37. }
  38. }
  39. }
  40. return { isSame, index }
  41. }
  42. // 判断是否是相同的星期
  43. const isSameWeek = (week, data) => {
  44. let isSame = false
  45. let index = null
  46. if (data.length > 0) {
  47. for (let i in data) {
  48. if (data[i]['week'] == week) {
  49. isSame = true
  50. index = i
  51. break
  52. }
  53. }
  54. }
  55. return { isSame, index }
  56. }
  57. // 判断是否是相同的星期 并且 传参日期要大于 当下日期
  58. const isSameWeekTwo = (week, date, data) => {
  59. let isSame = false
  60. let index = null
  61. if (data.length > 0) {
  62. for (let i in data) {
  63. if (data[i]['week'] == week && new Date(date.replace(/\-/g, "/")).getTime() >= new Date(data[i]['date'].replace(/\-/g, "/")).getTime()) {
  64. isSame = true
  65. index = i
  66. break
  67. }
  68. }
  69. }
  70. return { isSame, index }
  71. }
  72. // 判断是否是相同的一天
  73. const isSameDate = (date, data) => {
  74. let isSame = false
  75. let index = null
  76. if (data.length > 0) {
  77. for (let i in data) {
  78. if (data[i]['date'] == date) {
  79. isSame = true
  80. index = i
  81. break
  82. }
  83. }
  84. }
  85. return { isSame, index }
  86. }
  87. module.exports = {
  88. thisMonthLenth,
  89. startDate,
  90. isMaxDate,
  91. isSameWeek,
  92. isSameWeekTwo,
  93. isSameDate
  94. }