Skip to content

Commit 7eb0062

Browse files
committed
and generate dates with the correct timezone on android too
1 parent 8005d65 commit 7eb0062

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/views/components/datepicker/android.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Keyboard,
1111
StyleSheet,
1212
} from 'react-native'
13-
import moment from 'moment'
13+
import moment from 'moment-timezone'
1414
import * as c from '../colors'
1515
import type {StyleSheetRules} from './types'
1616

@@ -21,6 +21,7 @@ type Props = {
2121
mode: 'date' | 'datetime' | 'time',
2222
onDateChange: moment => any,
2323
style?: StyleSheetRules,
24+
timezone: string,
2425
}
2526

2627
type DatePickerResponse = {
@@ -48,15 +49,15 @@ export class AndroidDatePicker extends React.PureComponent<any, Props, void> {
4849
return
4950
}
5051

51-
this.props.onDateChange(moment({year, month, day}))
52+
this.props.onDateChange(moment.tz({year, month, day}, this.props.timezone))
5253
}
5354

5455
onTimePicked = ({action, hour, minute}: TimePickerResponse) => {
5556
if (action === DatePickerAndroid.dismissedAction) {
5657
return
5758
}
5859

59-
this.props.onDateChange(moment({hour, minute}))
60+
this.props.onDateChange(moment.tz({hour, minute}, this.props.timezone))
6061
}
6162

6263
onDatetimeDatePicked = ({action, year, month, day}: DatePickerResponse) => {
@@ -83,7 +84,9 @@ export class AndroidDatePicker extends React.PureComponent<any, Props, void> {
8384
return
8485
}
8586

86-
this.props.onDateChange(moment({year, month, day, hour, minute}))
87+
this.props.onDateChange(
88+
moment.tz({year, month, day, hour, minute}, this.props.timezone),
89+
)
8790
}
8891

8992
showModal = () => {

0 commit comments

Comments
 (0)