Skip to content

Commit 9fe0ea5

Browse files
committed
add support for HH:mm:ss format for input time fields
1 parent f8f708a commit 9fe0ea5

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

resources/js/packages/ui/src/TimeEntry/TimeEntryRowDurationInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const open = ref(false);
2929
function updateTimerAndStartLiveTimerUpdate() {
3030
const defaultUnit =
3131
organizationSettings?.value?.intervalFormat === 'decimal' ? 'hours' : 'minutes';
32-
const { seconds } = parseTimeInput(temporaryCustomTimerEntry.value, defaultUnit);
32+
const seconds = parseTimeInput(temporaryCustomTimerEntry.value, defaultUnit);
3333
if (seconds && seconds > 0) {
3434
let newEndDate = props.end;
3535
let newStartDate = props.start;

resources/js/packages/ui/src/TimeTracker/TimeTrackerRangeSelector.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const currentTime = computed({
5656
});
5757
5858
function updateTimerAndStartLiveTimerUpdate() {
59-
const { seconds } = parseTimeInput(temporaryCustomTimerEntry.value, 'minutes');
59+
const seconds = parseTimeInput(temporaryCustomTimerEntry.value, 'minutes');
6060
6161
if (seconds && seconds > 0) {
6262
const newStartDate = dayjs().subtract(seconds, 's');

resources/js/packages/ui/src/utils/time.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,30 @@ export function formatStartEnd(
208208
export function parseTimeInput(
209209
input: string,
210210
defaultUnit: TimeInputUnit = 'minutes'
211-
): {
212-
seconds: number | null;
213-
isHHMM: boolean;
214-
} {
211+
): number | null {
215212
// Check if input is a decimal number (hours)
216213
const decimalRegex = /^-?\d+[.,]\d+$/;
217214
if (decimalRegex.test(input)) {
218215
const hours = parseFloat(input.replace(',', '.'));
219-
return { seconds: Math.round(hours * 3600), isHHMM: false };
216+
return Math.round(hours * 3600);
220217
}
221218

222219
// Check if input is just a number (minutes or hours based on defaultUnit)
223220
if (/^-?\d+$/.test(input)) {
224221
const value = parseInt(input);
225-
const seconds = defaultUnit === 'minutes' ? value * 60 : value * 3600;
226-
return { seconds, isHHMM: false };
222+
return defaultUnit === 'minutes' ? value * 60 : value * 3600;
223+
}
224+
225+
// Check if input is in HH:MM:SS format
226+
const HHMMSStimeRegex = /^([0-9]{1,2}):([0-5]?[0-9]):([0-5]?[0-9])$/;
227+
if (HHMMSStimeRegex.test(input)) {
228+
const match = input.match(HHMMSStimeRegex);
229+
if (match) {
230+
const hours = parseInt(match[1]);
231+
const minutes = parseInt(match[2]);
232+
const seconds = parseInt(match[3]);
233+
return hours * 3600 + minutes * 60 + seconds;
234+
}
227235
}
228236

229237
// Check if input is in HH:MM format
@@ -233,15 +241,15 @@ export function parseTimeInput(
233241
if (match) {
234242
const hours = parseInt(match[1]);
235243
const minutes = parseInt(match[2]);
236-
return { seconds: (hours * 60 + minutes) * 60, isHHMM: true };
244+
return (hours * 60 + minutes) * 60;
237245
}
238246
}
239247

240248
// Try to parse natural language like "1h 30m"
241249
const parsedDuration = parse(input, 's');
242250
if (parsedDuration && parsedDuration > 0) {
243-
return { seconds: parsedDuration, isHHMM: false };
251+
return parsedDuration;
244252
}
245253

246-
return { seconds: null, isHHMM: false };
254+
return null;
247255
}

0 commit comments

Comments
 (0)