hooks.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import dayjs from './utils/dayjs'
  2. import { Period } from './types'
  3. import { useTranslation } from 'react-i18next'
  4. const YEAR_RANGE = 100
  5. export const useDaysOfWeek = () => {
  6. const { t } = useTranslation()
  7. const daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].map(day => t(`time.daysInWeek.${day}`))
  8. return daysOfWeek
  9. }
  10. export const useMonths = () => {
  11. const { t } = useTranslation()
  12. const months = [
  13. 'January',
  14. 'February',
  15. 'March',
  16. 'April',
  17. 'May',
  18. 'June',
  19. 'July',
  20. 'August',
  21. 'September',
  22. 'October',
  23. 'November',
  24. 'December',
  25. ].map(month => t(`time.months.${month}`))
  26. return months
  27. }
  28. export const useYearOptions = () => {
  29. const yearOptions = Array.from({ length: 200 }, (_, i) => dayjs().year() - YEAR_RANGE / 2 + i)
  30. return yearOptions
  31. }
  32. export const useTimeOptions = () => {
  33. const hourOptions = Array.from({ length: 12 }, (_, i) => (i + 1).toString().padStart(2, '0'))
  34. const minuteOptions = Array.from({ length: 60 }, (_, i) => i.toString().padStart(2, '0'))
  35. const periodOptions = [Period.AM, Period.PM]
  36. return {
  37. hourOptions,
  38. minuteOptions,
  39. periodOptions,
  40. }
  41. }