Skip to content

Commit

Permalink
fix: prevent default value handling from overwriting non-null/undefin…
Browse files Browse the repository at this point in the history
…ed falsy values
  • Loading branch information
kiki-kanri committed Aug 10, 2024
1 parent aae6482 commit a7b9c6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export const getDateRangeFromDate = (date: Date, type: DateRangeType, options?:
startDate = startOfMonth(lastMonth);
} else if (type === 'lastWeek') {
const lastWeek = subWeeks(date, 1);
endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn || 1 });
startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn || 1 });
endDate = endOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
startDate = startOfWeek(lastWeek, { weekStartsOn: options?.weekStartsOn ?? 1 });
} else if (type === 'thisMonth') {
endDate = endOfMonth(date);
startDate = startOfMonth(date);
} else if (type === 'thisWeek') {
endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn || 1 });
startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn || 1 });
endDate = endOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
startDate = startOfWeek(date, { weekStartsOn: options?.weekStartsOn ?? 1 });
} else if (type === 'today') {
endDate = endOfDay(date);
startDate = startOfDay(date);
Expand Down
4 changes: 2 additions & 2 deletions src/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export const calculateToPercentageString = (molecular: CalculableValue, denomina
const molecularDecimal = new Decimal(molecular.toString());
const denominatorDecimal = new Decimal(denominator.toString());
const calculationResult = molecularDecimal.div(denominatorDecimal);
const result = calculationResult.isNaN() ? '0.00' : calculationResult.times(100).toFixed(options?.decimalPlaces || 2);
return options?.withSymbol ?? true ? `${result}%` : result;
const result = calculationResult.isNaN() ? '0.00' : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);
return (options?.withSymbol ?? true) ? `${result}%` : result;
};

0 comments on commit a7b9c6e

Please sign in to comment.