Skip to content

Commit

Permalink
fix: format to max hours on blur instead of change
Browse files Browse the repository at this point in the history
  • Loading branch information
YejunWu168 committed Jul 16, 2021
1 parent 6bb311b commit 6c2045e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/records/weekly-timesheet-totals-row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default defineComponent({
.reduce((prevValue, value) => +prevValue + +value)
});
return total === 0 ? '0' : floatToTotalTimeString(total);
return floatToTotalTimeString(total);
});
const weekTheoreticalTotal = computed(() => {
Expand Down
13 changes: 5 additions & 8 deletions helpers/timesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function floatTo24TimeString(float: number) {
n.setMinutes(Math.round(float * 60));
const result = n.toTimeString()

return result !== "Invalid Date" ? result.slice(0, 5) : '';
return result !== "Invalid Date" ? result.slice(0, 5) : '0';
}

export function floatToTotalTimeString(float: number) {
Expand All @@ -193,7 +193,7 @@ export function floatToTotalTimeString(float: number) {
? +hoursMinutes[0] > 10
? hoursMinutes[0]
: `0${hoursMinutes[0]}`
: '';
: '00';

const formattedMinutes = Math.round(parseFloat(`0.${hoursMinutes[1]}`) * 60);
const minutes =
Expand Down Expand Up @@ -225,16 +225,13 @@ export function timesheetFormatter(min: number, max: number) {
formatter: (value: string, e: InputEvent) => {
const formatted = value.replace(/[^0-9.,:]+|\.(?=.*\.)/g, "");

if (formatted) {
const num = +value;
if (e.type === "blur") {
const numString = formatted.replace(",", ".");
const num = +numString;

if (num < min) return `0`;
if (num >= max) return `${max}:00`;
}

const numString = formatted.replace(",", ".");

if (e.type === "blur") {
if (numString.match(/^[0]+$/) || numString === '.') return "0";
if (!numString.match(/[:]/)) {
return floatTo24TimeString(+numString);
Expand Down

0 comments on commit 6c2045e

Please sign in to comment.