@@ -12,9 +12,7 @@ import {
1212 getAngle ,
1313 getHours ,
1414 getHourType ,
15- getHourTypeFromOffset ,
1615 getMinutes ,
17- hourTypes ,
1816 PossibleClockTypes ,
1917} from './timeUtils'
2018import * as React from 'react'
@@ -24,6 +22,7 @@ import AnalogClockHours from './AnalogClockHours'
2422
2523import AnimatedClockSwitcher from './AnimatedClockSwitcher'
2624import AnalogClockMinutes from './AnalogClockMinutes'
25+ import { DisplayModeContext } from './TimePicker'
2726
2827function AnalogClock ( {
2928 hours,
@@ -47,7 +46,7 @@ function AnalogClock({
4746 } ) => any
4847} ) {
4948 const theme = useTheme ( )
50-
49+ const { mode } = React . useContext ( DisplayModeContext )
5150 // used to make pointer shorter if hours are selected and above 12
5251 const shortPointer = ( hours === 0 || hours > 12 ) && is24Hour
5352
@@ -60,6 +59,7 @@ function AnalogClock({
6059 const minutesRef = useLatest ( minutes )
6160 const focusedRef = useLatest ( focused )
6261 const is24HourRef = useLatest ( is24Hour )
62+ const modeRef = useLatest ( mode )
6363
6464 const onPointerMove = React . useCallback (
6565 ( e : GestureResponderEvent , final : boolean ) => {
@@ -73,12 +73,10 @@ function AnalogClock({
7373 let previousHourType = getHourType ( hoursRef . current )
7474 let pickedHours = getHours ( angle , previousHourType )
7575
76- let hourTypeFromOffset = getHourTypeFromOffset ( x , y , circleSize )
77- let hours24AndPM = hours24 && hourTypeFromOffset === hourTypes . pm
78- let hours12AndPm = ! hours24 && previousHourType === hourTypes . pm
79-
80- // TODO: check which mode is switched on am/pm
81- if ( hours12AndPm || hours24AndPM ) {
76+ let hours12AndPm = ! hours24 && modeRef . current === 'PM'
77+ // Avoiding the "24h"
78+ // Should be 12h for 12 hours and PM mode
79+ if ( ( hours12AndPm || hours24 ) && pickedHours + 12 < 24 ) {
8280 pickedHours += 12
8381 }
8482
@@ -103,7 +101,7 @@ function AnalogClock({
103101 }
104102 }
105103 } ,
106- [ focusedRef , is24HourRef , hoursRef , onChangeRef , minutesRef ]
104+ [ focusedRef , is24HourRef , hoursRef , onChangeRef , minutesRef , modeRef ]
107105 )
108106
109107 const panResponder = React . useRef (
0 commit comments