feat: add weekday constants and helpers
This commit is contained in:
17
src/lib/weekday.js
Normal file
17
src/lib/weekday.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// JS getDay() index: 0=Sunday .. 6=Saturday
|
||||
export const DOW = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||
|
||||
// BYDAY codes indexed by JS getDay(): DOW_EN[getDay()] => 'SU'..'SA'
|
||||
export const DOW_EN = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA']
|
||||
|
||||
export const BYDAY_TO_INDEX = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 }
|
||||
|
||||
/** Return the BYDAY code ('SU'..'SA') for a JS Date. */
|
||||
export function bydayFromDate(date) {
|
||||
return DOW_EN[date.getDay()]
|
||||
}
|
||||
|
||||
/** Return the Chinese weekday label for a JS Date. */
|
||||
export function dowLabel(date) {
|
||||
return DOW[date.getDay()]
|
||||
}
|
||||
Reference in New Issue
Block a user