Skip to content

Commit adc66d0

Browse files
Merge pull request #230 from web-ridge/hour-formatting-bugfix
Roll out fixes for 12 hour formatting.
2 parents 149f55f + 7e32eeb commit adc66d0

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/Time/AnalogClock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function AnalogClock({
6363
let previousHourType = getHourType(hoursRef.current)
6464
let pickedHours = getHours(angle, previousHourType)
6565

66-
let hours12AndPm = !hours24 && modeRef.current === 'AM'
66+
let hours12AndPm = !hours24 && modeRef.current === 'PM'
6767

6868
let hourTypeFromOffset = getHourTypeFromOffset(x, y, circleSize)
6969
let hours24AndPM = hours24 && hourTypeFromOffset === hourTypes.pm

src/Time/AnalogClockHours.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function AnalogClockHours({
3838
variant="bodyLarge"
3939
selectable={false}
4040
>
41-
{mode === 'AM' && !is24Hour && i + 1 === 12 ? '00' : i + 1}
41+
{mode === 'AM' && is24Hour && i + 1 === 12 ? '00' : i + 1}
4242
</Text>
4343
</View>
4444
</View>

src/Time/timeUtils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,18 @@ export function useInputColors(highlighted: boolean) {
242242
}
243243

244244
export function toHourInputFormat(hours: number, is24Hour: boolean): number {
245-
if (hours === 24) {
246-
return 0
247-
}
248245
if (is24Hour) {
246+
if (hours === 24) {
247+
return 0
248+
}
249249
return hours
250250
}
251251
if (hours > 12) {
252252
return hours - 12
253253
}
254+
if (hours === 0) {
255+
return hours + 12
256+
}
254257
return hours
255258
}
256259

@@ -262,7 +265,7 @@ export function toHourOutputFormat(
262265
if (is24Hour) {
263266
return newHours
264267
}
265-
if (previousHours > 12 && newHours < 12) {
268+
if ((!is24Hour && previousHours === 0) || newHours === 0) {
266269
return newHours + 12
267270
}
268271
return newHours

src/__tests__/Time/__snapshots__/AnalogClock.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ exports[`renders AnalogClock 1`] = `
794794
]
795795
}
796796
>
797-
00
797+
12
798798
</Text>
799799
</View>
800800
</View>

src/__tests__/Time/__snapshots__/AnalogClockHours.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ exports[`renders AnalogClockHours 1`] = `
660660
]
661661
}
662662
>
663-
12
663+
00
664664
</Text>
665665
</View>
666666
</View>,

src/__tests__/Time/timeUtils.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('timeUtils', () => {
7878
})
7979

8080
it('should return correct hour output format when not is24Hour', () => {
81-
expect(toHourOutputFormat(11, 13, false)).toBe(23)
81+
expect(toHourOutputFormat(11, 13, false)).toBe(11)
8282
})
8383

8484
it('should return correct hour output format when is24Hour', () => {

0 commit comments

Comments
 (0)