@startupjs-ui/date-time-picker 0.1.3 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.1.7](https://github.com/startupjs/startupjs-ui/compare/v0.1.6...v0.1.7) (2026-01-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **date-time-picker:** use async import for 'moment-timezone' since it's too large to go into the core bundle by default ([0de6908](https://github.com/startupjs/startupjs-ui/commit/0de690895a6870d4b5bd4a8a6744d9dc61547c17))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.1.5](https://github.com/startupjs/startupjs-ui/compare/v0.1.4...v0.1.5) (2025-12-29)
18
+
19
+ **Note:** Version bump only for package @startupjs-ui/date-time-picker
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.1.3](https://github.com/startupjs/startupjs-ui/compare/v0.1.2...v0.1.3) (2025-12-29)
7
26
 
8
27
  **Note:** Version bump only for package @startupjs-ui/date-time-picker
@@ -2,7 +2,7 @@ import { useMemo, useCallback, type ReactNode } from 'react'
2
2
  import { pug, observer } from 'startupjs'
3
3
  import Span from '@startupjs-ui/span'
4
4
  import Div from '@startupjs-ui/div'
5
- import moment from 'moment-timezone'
5
+ import { useMoment } from '../../../helpers'
6
6
  import './index.cssx.styl'
7
7
 
8
8
  interface DaysProps {
@@ -28,10 +28,11 @@ function Days ({
28
28
  range,
29
29
  onChangeDate
30
30
  }: DaysProps): ReactNode {
31
+ const moment = useMoment()
31
32
  const weekdaysShort = useMemo(() => {
32
33
  const data = (moment
33
34
  .tz(uiDate, timezone)
34
- .locale(exactLocale) as any)
35
+ .locale(exactLocale))
35
36
  ._locale
36
37
  ._weekdaysShort
37
38
 
@@ -9,7 +9,7 @@ import Span from '@startupjs-ui/span'
9
9
  import { faAngleLeft } from '@fortawesome/free-solid-svg-icons/faAngleLeft'
10
10
  import { faAngleRight } from '@fortawesome/free-solid-svg-icons/faAngleRight'
11
11
  import { faCaretDown } from '@fortawesome/free-solid-svg-icons/faCaretDown'
12
- import moment from 'moment-timezone'
12
+ import { useMoment } from '../../../helpers'
13
13
  import STYLES from './index.cssx.styl'
14
14
 
15
15
  const yearsItemStyle = STYLES['years-item']
@@ -32,6 +32,7 @@ function Header ({
32
32
  maxDate,
33
33
  $uiDate
34
34
  }: HeaderProps): ReactNode {
35
+ const moment = useMoment()
35
36
  const monthName = moment.tz(uiDate, timezone).locale(exactLocale).format('MMM')
36
37
 
37
38
  const onChangeMonth = useCallback((value: number) => {
@@ -92,6 +93,7 @@ const Years = observer(function YearsComponent ({
92
93
  timezone,
93
94
  $uiDate
94
95
  }: YearsProps): ReactNode {
96
+ const moment = useMoment()
95
97
  const $visible = $(false)
96
98
  const minYear = minDate ? moment.tz(minDate, timezone).year() : 1950
97
99
  const maxYear = maxDate ? moment.tz(maxDate, timezone).year() : 2050
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from 'react'
2
2
  import { pug, observer, $ } from 'startupjs'
3
3
  import Div from '@startupjs-ui/div'
4
- import moment from 'moment-timezone'
4
+ import { useMoment } from '../../helpers'
5
5
  import Header from './Header'
6
6
  import Days from './Days'
7
7
 
@@ -28,6 +28,7 @@ function Calendar ({
28
28
  testID,
29
29
  onChangeDate
30
30
  }: CalendarProps): ReactNode {
31
+ const moment = useMoment()
31
32
  const $uiDate = $(+moment(date).seconds(0).milliseconds(0))
32
33
 
33
34
  return pug`
@@ -11,7 +11,7 @@ import { pug, observer } from 'startupjs'
11
11
  import Div from '@startupjs-ui/div'
12
12
  import FlatList from '@startupjs-ui/flat-list'
13
13
  import Span from '@startupjs-ui/span'
14
- import moment from 'moment-timezone'
14
+ import { useMoment } from '../../helpers'
15
15
  import STYLES from './index.cssx.styl'
16
16
 
17
17
  export interface TimeSelectRef {
@@ -42,13 +42,14 @@ function TimeSelect ({
42
42
  onChangeDate,
43
43
  ref
44
44
  }: TimeSelectProps): ReactNode {
45
+ const moment = useMoment()
45
46
  const refScroll = useRef<any>(null)
46
47
 
47
48
  // we are looking for 'a' in current locale
48
49
  // to figure out whether to apply 12 hour format
49
50
  const _is24Hour = useMemo(() => {
50
51
  if (is24Hour != null) return is24Hour
51
- const lt = (moment().locale(exactLocale) as any)._locale._longDateFormat.LT
52
+ const lt = (moment().locale(exactLocale))._locale._longDateFormat.LT
52
53
  return !/a/i.test(lt)
53
54
  }, [is24Hour, exactLocale])
54
55
 
@@ -60,7 +61,7 @@ function TimeSelect ({
60
61
  const intervalTimestamp = timeInterval * 60 * 1000
61
62
 
62
63
  const format = _is24Hour
63
- ? (moment.tz(date, timezone).locale(exactLocale) as any)._locale._longDateFormat.LT
64
+ ? (moment.tz(date, timezone).locale(exactLocale))._locale._longDateFormat.LT
64
65
  : 'hh:mm A'
65
66
 
66
67
  while (currentTimestamp < endTimestamp) {
package/helpers/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default as getLocale } from './getLocale'
2
+ export { default as useMoment } from './useMoment'
@@ -0,0 +1,12 @@
1
+ import { use } from 'react'
2
+
3
+ let momentPromise: any
4
+
5
+ const loadMoment = (): Promise<any> => { // eslint-disable-line @typescript-eslint/promise-function-async
6
+ if (!momentPromise) momentPromise = import('moment-timezone').then(m => m.default)
7
+ return momentPromise
8
+ }
9
+
10
+ export default function useMoment () {
11
+ return use(loadMoment())
12
+ }
package/index.tsx CHANGED
@@ -19,8 +19,7 @@ import TextInput, { type UITextInputProps } from '@startupjs-ui/text-input'
19
19
  import AbstractPopover from '@startupjs-ui/abstract-popover'
20
20
  import Drawer from '@startupjs-ui/drawer'
21
21
  import { faTimesCircle } from '@fortawesome/free-solid-svg-icons/faTimesCircle'
22
- import moment from 'moment-timezone'
23
- import { getLocale } from './helpers'
22
+ import { getLocale, useMoment } from './helpers'
24
23
  import { Calendar, TimeSelect } from './components'
25
24
  import './index.cssx.styl'
26
25
 
@@ -101,7 +100,7 @@ function DateTimePicker ({
101
100
  renderInput,
102
101
  locale,
103
102
  range,
104
- timezone = moment.tz.guess(),
103
+ timezone,
105
104
  disabledDays = [],
106
105
  date,
107
106
  disabled,
@@ -121,6 +120,8 @@ function DateTimePicker ({
121
120
  ref,
122
121
  ...props
123
122
  }: DateTimePickerProps): ReactNode {
123
+ const moment = useMoment()
124
+ timezone ??= moment.tz.guess()
124
125
  const media: any = useMedia()
125
126
  const [textInput, setTextInput] = useState('')
126
127
  const refTimeSelect = useRef<any>(null)
@@ -239,7 +240,7 @@ function DateTimePicker ({
239
240
  let { onChangeVisible } = bindProps
240
241
  ;({ visible, onChangeVisible } = useBind({ $visible, visible, onChangeVisible }) as any)
241
242
 
242
- const [tempDate, setTempDate] = useTempDate({ visible: !!visible, date, timezone })
243
+ const [tempDate, setTempDate] = useTempDate({ visible: !!visible, date, timezone: timezone as any, moment })
243
244
 
244
245
  useEffect(() => {
245
246
  // Prevent crashes when custom renderer passed via props
@@ -260,12 +261,12 @@ function DateTimePicker ({
260
261
  const _dateFormat = useMemo(() => {
261
262
  if (dateFormat) return dateFormat
262
263
  if (mode === 'datetime') {
263
- return (moment().locale(exactLocale) as any)._locale._longDateFormat.L + ' ' +
264
- (moment().locale(exactLocale) as any)._locale._longDateFormat.LT
264
+ return (moment().locale(exactLocale))._locale._longDateFormat.L + ' ' +
265
+ (moment().locale(exactLocale))._locale._longDateFormat.LT
265
266
  }
266
267
 
267
- if (mode === 'date') return (moment().locale(exactLocale) as any)._locale._longDateFormat.L
268
- if (mode === 'time') return (moment().locale(exactLocale) as any)._locale._longDateFormat.LT
268
+ if (mode === 'date') return (moment().locale(exactLocale))._locale._longDateFormat.L
269
+ if (mode === 'time') return (moment().locale(exactLocale))._locale._longDateFormat.LT
269
270
  }, [mode, dateFormat, exactLocale])
270
271
 
271
272
  useEffect(() => {
@@ -462,23 +463,25 @@ function DateTimePicker ({
462
463
  function useTempDate ({
463
464
  visible,
464
465
  date,
465
- timezone
466
+ timezone,
467
+ moment
466
468
  }: {
467
469
  visible: boolean
468
470
  date?: number
469
471
  timezone: string
472
+ moment: any
470
473
  }) {
471
- const [tempDate, setTempDate] = useState(getTempDate(date, timezone))
474
+ const [tempDate, setTempDate] = useState(getTempDate(date, timezone, moment))
472
475
 
473
476
  useEffect(() => {
474
- const tempDate = getTempDate(date, timezone)
477
+ const tempDate = getTempDate(date, timezone, moment)
475
478
  setTempDate(tempDate)
476
- }, [visible, date, timezone])
479
+ }, [visible, date, timezone, moment])
477
480
 
478
481
  return [tempDate, setTempDate] as const
479
482
  }
480
483
 
481
- function getTempDate (date: number | undefined, timezone: string) {
484
+ function getTempDate (date: number | undefined, timezone: string, moment: any) {
482
485
  return date
483
486
  ? new Date(+moment.tz(date, timezone).seconds(0).milliseconds(0))
484
487
  : new Date()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startupjs-ui/date-time-picker",
3
- "version": "0.1.3",
3
+ "version": "0.1.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,17 +10,17 @@
10
10
  "dependencies": {
11
11
  "@fortawesome/free-solid-svg-icons": "^5.12.0",
12
12
  "@react-native-community/datetimepicker": "^8.4.4",
13
- "@startupjs-ui/abstract-popover": "^0.1.3",
14
- "@startupjs-ui/button": "^0.1.3",
15
- "@startupjs-ui/core": "^0.1.3",
16
- "@startupjs-ui/div": "^0.1.3",
17
- "@startupjs-ui/divider": "^0.1.3",
18
- "@startupjs-ui/drawer": "^0.1.3",
19
- "@startupjs-ui/flat-list": "^0.1.3",
20
- "@startupjs-ui/icon": "^0.1.3",
21
- "@startupjs-ui/popover": "^0.1.3",
22
- "@startupjs-ui/span": "^0.1.3",
23
- "@startupjs-ui/text-input": "^0.1.3",
13
+ "@startupjs-ui/abstract-popover": "^0.1.5",
14
+ "@startupjs-ui/button": "^0.1.5",
15
+ "@startupjs-ui/core": "^0.1.5",
16
+ "@startupjs-ui/div": "^0.1.5",
17
+ "@startupjs-ui/divider": "^0.1.5",
18
+ "@startupjs-ui/drawer": "^0.1.5",
19
+ "@startupjs-ui/flat-list": "^0.1.5",
20
+ "@startupjs-ui/icon": "^0.1.5",
21
+ "@startupjs-ui/popover": "^0.1.5",
22
+ "@startupjs-ui/span": "^0.1.5",
23
+ "@startupjs-ui/text-input": "^0.1.5",
24
24
  "moment-timezone": "^0.5.31",
25
25
  "react-native-safe-area-context": "^5.6.0"
26
26
  },
@@ -29,5 +29,5 @@
29
29
  "react-native": "*",
30
30
  "startupjs": "*"
31
31
  },
32
- "gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
32
+ "gitHead": "9c2c4a204f9f0b6650f02f6d4948780cced7cd8d"
33
33
  }