From 6f97ee1aeba759c37112a1ad5fc4df5bc75c8b83 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Fri, 22 Mar 2024 18:33:25 -0300 Subject: [PATCH] improvements --- src/filters/date.js | 21 ++++++++++ src/pages/Worker/Card/WorkerTimeControl.vue | 45 +++++++++------------ 2 files changed, 41 insertions(+), 25 deletions(-) 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 () => {
{ @click="isSatisfied()" /> { @click="showReasonForm()" /> { ) " > - {{ state ? t('Resend') : t('globals.send') }} - {{ t('email of this week to the user') }} + + {{ state ? t('Resend') : t('globals.send') }} + {{ t('email of this week to the user') }} +
@@ -522,7 +518,7 @@ onMounted(async () => { : {{ formattedWeekTotalHours }}
- {{ t('Termina a las') }}: + {{ t('Termina a las') }}: {{ dashIfEmpty(getFinishTime()) }}
@@ -541,7 +537,6 @@ onMounted(async () => { dense :default-year-month="defaultDate" /> -
date range: {{ selectedCalendarDates }}
@@ -557,12 +552,12 @@ onMounted(async () => {
{{ t(col.label) }} {{ col.formattedDate }} - {{ col.dayData.event.name }} - +
@@ -572,7 +567,7 @@ onMounted(async () => {
{
- {{ formatHours(day.dayData?.workedHours) }} + {{ secondsToHoursMinutes(day.dayData?.workedHours) }}