Skip to content

Commit

Permalink
Revert "Merge pull request #5597 from Alanscut:issue-5596"
Browse files Browse the repository at this point in the history
This reverts commit b4e0676, reversing
changes made to cbcd0c5.
  • Loading branch information
ichernev committed Dec 26, 2023
1 parent 8dd12f6 commit 15b82f5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
8 changes: 3 additions & 5 deletions src/lib/duration/constructor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { normalizeObjectUnits } from '../units/aliases';
import { getLocale } from '../locale/locales';
import isDurationValid from './valid.js';
import multiply from '../utils/float-calculate';

export function Duration(duration) {
var normalizedInput = normalizeObjectUnits(duration),
Expand All @@ -20,10 +19,9 @@ export function Duration(duration) {
// representation for dateAddRemove
this._milliseconds =
+milliseconds +
// reduce floating point rounding errors
multiply(seconds, 1e3) +
multiply(minutes, 6e4) +
multiply(hours, 36e5);
seconds * 1e3 + // 1000
minutes * 6e4 + // 1000 * 60
hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
// Because of dateAddRemove treats 24 hours as different from a
// day when working around DST, we need to store them separately
this._days = +days + weeks * 7;
Expand Down
33 changes: 0 additions & 33 deletions src/lib/utils/float-calculate.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/moment/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,6 @@ test('instantiation from another duration', function (assert) {
});

test('explicit cloning', function (assert) {
var duration = moment.duration(1.1234, 'hours');
assert.equal(
duration.milliseconds(),
240,
'Float number calculation will not lose accuracy'
);
});

test('float number calculation', function (assert) {
var durationA = moment.duration(5, 'milliseconds'),
durationB = durationA.clone();
durationA.add(5, 'milliseconds');
Expand Down

0 comments on commit 15b82f5

Please sign in to comment.