Skip to content

Commit

Permalink
feat(date-utils): default rounding logic to nearest
Browse files Browse the repository at this point in the history
  • Loading branch information
z3bi committed Jun 16, 2021
1 parent 7cf40d4 commit 87f2b99
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export function dateByAddingSeconds(date, seconds) {

export function roundedMinute(date, rounding = Rounding.Nearest) {
const seconds = date.getUTCSeconds();
let offset = 0;
if (rounding === Rounding.Nearest) {
offset = seconds >= 30 ? 60 - seconds : -1 * seconds;
} else if (rounding === Rounding.Up) {
let offset = seconds >= 30 ? 60 - seconds : -1 * seconds;
if (rounding === Rounding.Up) {
offset = 60 - seconds;
} else if (rounding === Rounding.None) {
offset = 0;
}

return dateByAddingSeconds(date, offset);
Expand Down

0 comments on commit 87f2b99

Please sign in to comment.