From 94b19f988afe81e8cb514a4b690bdb1c3f88c278 Mon Sep 17 00:00:00 2001 From: Dmytro Kardava Date: Fri, 3 Feb 2023 14:02:44 +0100 Subject: [PATCH] fix default 12 hour display --- package.json | 2 +- src/components/Hours.tsx | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 814568d..0f5460c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-calendar-timetable", "description": "Timetable (schedule) component for React Native applications", - "version": "1.0.3", + "version": "1.0.4", "private": false, "main": "./lib/Timetable.js", "types": "./lib/Timetable.d.ts", diff --git a/src/components/Hours.tsx b/src/components/Hours.tsx index 96ea8d7..9b8a133 100644 --- a/src/components/Hours.tsx +++ b/src/components/Hours.tsx @@ -21,9 +21,17 @@ function Hours({ }: HoursProps) { const timeFontSize = timeStyle?.fontSize || 14; - const renderTime = (hour: number) => is12Hour - ? (hour > 12 ? (hour - 12 + ' pm') : hour + ' am') - : (hour > 9 ? '' : '0') + (hour === 24 ? '00' : hour) + ':00'; + const renderTime = (hour: number) => { + if (is12Hour) { + switch (hour) { + case 0: case 24: return '12 am'; + case 12: return '12 pm'; + default: + return (hour > 12 ? (hour - 12 + ' pm') : hour + ' am'); + } + } + return (hour > 9 ? '' : '0') + (hour === 24 ? '00' : hour) + ':00'; + }; return (