1 |
- {"version":3,"file":"dateTimeUtils.mjs","names":["createRange","padStart","getFirstDayOfMonth","year","month","Date","getLastDayOfMonth","getNumberOfDaysInMonth","getDate","changeMonth","change","day","String","addDays","date","days","d","setDate","getFullYear","getMonth","parseDate","split","map","Number","getMondayOfFirstWeekOfYear","januaryFirst","mondayOfFirstWeek","getDay","getWeek","d1w1","tv","diffTime","Math","abs","getTime","diffDays","ceil","floor","getDaysInMonth","createUTCDate","arguments","length","undefined","UTC","isFinite","getUTCFullYear","setUTCFullYear","firstWeekOffset","firstDayOfWeek","firstDayOfYear","firstWeekDayInFirstWeek","firstWeekDayOfYear","getUTCDay","dayOfYear","isLeapYear","weeksInYear","weekOffset","weekOffsetNext","daysInYear","weekNumber","localeFirstDayOfYear","week"],"sources":["../../src/util/dateTimeUtils.ts"],"sourcesContent":["// Utilities\nimport { createRange, padStart } from '@/util'\n\nexport function getFirstDayOfMonth (year: number, month: number) {\n return new Date(year, month, 1)\n}\n\nexport function getLastDayOfMonth (year: number, month: number) {\n return new Date(year, month + 1, 0)\n}\n\nfunction getNumberOfDaysInMonth (year: number, month: number) {\n return new Date(year, month, 0).getDate()\n}\n\nexport function changeMonth (year: number, month: number, change: number) {\n if (change < 0 && month + change < 1) {\n return [year - 1, 12 + (month + change)]\n } else if (change > 0 && month + change > 12) {\n return [year + 1, (month + change) % 12]\n } else {\n return [year, month + change]\n }\n}\n\nexport function getDate (year: number, month: number, day: number) {\n return `${year}-${padStart(String(month), 2, '0')}-${padStart(String(day), 2, '0')}`\n}\n\nexport function addDays (date: string, days: number) {\n const d = new Date(date)\n\n d.setDate(d.getDate() + days)\n\n return getDate(d.getFullYear(), d.getMonth() + 1, d.getDate())\n}\n\nexport function parseDate (date: string): [number, number, number] {\n const [year, month, day] = date.split('-').map(Number)\n\n return [year, month, day]\n}\n\nfunction getMondayOfFirstWeekOfYear (year: number) {\n const januaryFirst = new Date(year, 0, 1)\n const mondayOfFirstWeek = new Date(januaryFirst)\n\n mondayOfFirstWeek.setDate(mondayOfFirstWeek.getDate() + ((11 - januaryFirst.getDay()) % 7) - 3)\n\n return mondayOfFirstWeek\n}\n\n// https://stackoverflow.com/questions/274861/how-do-i-calculate-the-week-number-given-a-date/275024#275024\nexport function getWeek (date: Date) {\n let year = date.getFullYear()\n let d1w1 = getMondayOfFirstWeekOfYear(year)\n\n if (date < d1w1) {\n year = year - 1\n d1w1 = getMondayOfFirstWeekOfYear(year)\n } else {\n const tv = getMondayOfFirstWeekOfYear(year + 1)\n if (date >= tv) {\n year = year + 1\n d1w1 = tv\n }\n }\n\n const diffTime = Math.abs(date.getTime() - d1w1.getTime())\n const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))\n\n return Math.floor(diffDays / 7) + 1\n}\n\nexport function getDaysInMonth (year: number, month: number) {\n return createRange(getNumberOfDaysInMonth(year, month), 1).map(day => ({\n year,\n month,\n day,\n date: getDate(year, month, day),\n }))\n}\n\n// old\n\nfunction createUTCDate (year: number, month = 0, day = 1) {\n let date\n if (year < 100 && year >= 0) {\n date = new Date(Date.UTC(year, month, day))\n if (isFinite(date.getUTCFullYear())) {\n date.setUTCFullYear(year)\n }\n } else {\n date = new Date(Date.UTC(year, month, day))\n }\n\n return date\n}\n\nfunction firstWeekOffset (year: number, firstDayOfWeek: number, firstDayOfYear: number) {\n const firstWeekDayInFirstWeek = 7 + firstDayOfWeek - firstDayOfYear\n const firstWeekDayOfYear = (7 + createUTCDate(year, 0, firstWeekDayInFirstWeek).getUTCDay() - firstDayOfWeek) % 7\n\n return -firstWeekDayOfYear + firstWeekDayInFirstWeek - 1\n}\n\nfunction dayOfYear (year: number, month: number, day: number, firstDayOfWeek: number) {\n let dayOfYear = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334][month]\n if (month > 1 && isLeapYear(year)) {\n dayOfYear++\n }\n\n return dayOfYear + day\n}\n\nfunction weeksInYear (year: number, firstDayOfWeek: number, firstDayOfYear: number) {\n const weekOffset = firstWeekOffset(year, firstDayOfWeek, firstDayOfYear)\n const weekOffsetNext = firstWeekOffset(year + 1, firstDayOfWeek, firstDayOfYear)\n const daysInYear = isLeapYear(year) ? 366 : 365\n\n return (daysInYear - weekOffset + weekOffsetNext) / 7\n}\n\nexport function weekNumber (year: number, month: number, day: number, firstDayOfWeek: number, localeFirstDayOfYear: number): number {\n const weekOffset = firstWeekOffset(year, firstDayOfWeek, localeFirstDayOfYear)\n const week = Math.ceil((dayOfYear(year, month, day, firstDayOfWeek) - weekOffset) / 7)\n\n if (week < 1) {\n return week + weeksInYear(year - 1, firstDayOfWeek, localeFirstDayOfYear)\n } else if (week > weeksInYear(year, firstDayOfWeek, localeFirstDayOfYear)) {\n return week - weeksInYear(year, firstDayOfWeek, localeFirstDayOfYear)\n } else {\n return week\n }\n}\n\nexport function isLeapYear (year: number): boolean {\n return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0)\n}\n"],"mappings":"AAAA;AAAA,SACSA,WAAW,EAAEC,QAAQ;AAE9B,OAAO,SAASC,kBAAkBA,CAAEC,IAAY,EAAEC,KAAa,EAAE;EAC/D,OAAO,IAAIC,IAAI,CAACF,IAAI,EAAEC,KAAK,EAAE,CAAC,CAAC;AACjC;AAEA,OAAO,SAASE,iBAAiBA,CAAEH,IAAY,EAAEC,KAAa,EAAE;EAC9D,OAAO,IAAIC,IAAI,CAACF,IAAI,EAAEC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;AACrC;AAEA,SAASG,sBAAsBA,CAAEJ,IAAY,EAAEC,KAAa,EAAE;EAC5D,OAAO,IAAIC,IAAI,CAACF,IAAI,EAAEC,KAAK,EAAE,CAAC,CAAC,CAACI,OAAO,EAAE;AAC3C;AAEA,OAAO,SAASC,WAAWA,CAAEN,IAAY,EAAEC,KAAa,EAAEM,MAAc,EAAE;EACxE,IAAIA,MAAM,GAAG,CAAC,IAAIN,KAAK,GAAGM,MAAM,GAAG,CAAC,EAAE;IACpC,OAAO,CAACP,IAAI,GAAG,CAAC,EAAE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