time input: add formatTime helper
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
<script lang="ts" module>
|
||||
/**
|
||||
* formatTime returns a human readable 12-hour based string.
|
||||
*
|
||||
* @param time The time to format, can be null or undefined.
|
||||
* @param fallback Optional fallback string to return if time is null or undefined.
|
||||
* If not provided, an empty string will be returned.
|
||||
* If provided, it will be returned when time is null or undefined.
|
||||
* @returns The time in 12-hour format or the fallback string if undefined.
|
||||
*/
|
||||
export const formatTime = (time: Time | null | undefined, fallback?: string): string => {
|
||||
if (!time) return fallback ?? '';
|
||||
return moment(time.toString(), 'HH:mm:ss').format('h:mm A');
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { liveValidator, validate } from '@svelte-toolkit/validate';
|
||||
import Label from './Label.svelte';
|
||||
@@ -153,8 +169,7 @@
|
||||
updateHiddenInput();
|
||||
|
||||
// update formatted value
|
||||
const date = moment(value, 'HH:mm');
|
||||
formattedValue = date.format('h:mm A');
|
||||
formattedValue = formatTime(value);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user