diff --git a/src/filters/date.js b/src/filters/date.js index 337e1d876..d739aec57 100644 --- a/src/filters/date.js +++ b/src/filters/date.js @@ -91,3 +91,24 @@ export function toDateTimeFormat(date, showSeconds = false) { second: showSeconds ? '2-digit' : undefined, }); } + +/** + * Converts seconds to a formatted string representing hours and minutes (hh:mm). + * @param {number} seconds - The number of seconds to convert. + * @param {boolean} includeHSuffix - Optional parameter indicating whether to include "h." after the hour. + * @returns {string} A string representing the time in the format "hh:mm" with optional "h." suffix. + */ +export function secondsToHoursMinutes(seconds, includeHSuffix = true) { + if (!seconds) return includeHSuffix ? '00:00 h.' : '00:00'; + + const hours = Math.floor(seconds / 3600); + const remainingMinutes = seconds % 3600; + const minutes = Math.floor(remainingMinutes / 60); + const formattedHours = hours < 10 ? '0' + hours : hours; + const formattedMinutes = minutes < 10 ? '0' + minutes : minutes; + + // Append "h." if includeHSuffix is true + const suffix = includeHSuffix ? ' h.' : ''; + // Return formatted string + return formattedHours + ':' + formattedMinutes + suffix; +} diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index b616141aa..ea7db316c 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -17,10 +17,10 @@ import { useState } from 'src/composables/useState'; import { dashIfEmpty } from 'src/filters'; import { useVnConfirm } from 'composables/useVnConfirm'; import { useArrayData } from 'composables/useArrayData'; -import { toTimeFormat } from 'filters/date.js'; +import { toTimeFormat, secondsToHoursMinutes } from 'filters/date.js'; const route = useRoute(); -const { t } = useI18n(); +const { t, locale } = useI18n(); const { notify } = useNotify(); const { hasAny } = useRole(); const _state = useState(); @@ -75,16 +75,13 @@ const columns = computed(() => { const getHeaderFormattedDate = (date) => { const newDate = new Date(date); const day = String(newDate.getDate()).padStart(2, '0'); - const monthName = newDate.toLocaleString('es-ES', { month: 'long' }); + const monthName = newDate.toLocaleString(locale.value, { month: 'long' }); return `${day} ${monthName}`; }; -const formatHours = (hour = 0) => { - const _hour = toTimeFormat(hour); - return _hour ? `${_hour} h.` : '00:00 h.'; -}; - -const formattedWeekTotalHours = computed(() => formatHours(weekTotalHours.value)); +const formattedWeekTotalHours = computed(() => + secondsToHoursMinutes(weekTotalHours.value) +); const defaultDate = computed(() => { const date = Date.vnNew(); @@ -211,7 +208,6 @@ const getWorkedHours = async (from, to) => { weekDay.workedHours = workDay.workedHours; } } - weekTotalHours.value = _weekTotalHours; }; @@ -358,7 +354,7 @@ const getFinishTime = () => { const finishTimeStamp = lastKnownTime && remainingTime ? lastKnownTime + remainingTime : null; - if (finishTimeStamp) return formatHours(finishTimeStamp); + if (finishTimeStamp) return toTimeFormat(finishTimeStamp) + ' h.'; } }; @@ -466,7 +462,7 @@ onMounted(async () => {
date range: {{ selectedCalendarDates }}