Skip to content

Commit 11d0321

Browse files
author
Greg S
committed
#44: use LocalDateTime rather than Date for unit test expected data source
1 parent 7761b89 commit 11d0321

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/model/transaction/Deadline.spec.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
*/
1616

1717
import {expect} from 'chai';
18-
import {ChronoUnit} from 'js-joda';
18+
import {ChronoUnit, Instant, LocalDateTime, ZoneId} from 'js-joda';
1919
import {Deadline} from '../../../src/model/transaction/Deadline';
2020

2121
describe('Deadline', () => {
2222
it('should createComplete timestamp today', () => {
2323
const deadline = Deadline.create();
24-
const date = new Date();
25-
expect(deadline.value.dayOfMonth()).to.be.equal(date.getDate());
26-
expect(deadline.value.monthValue()).to.be.equal(date.getMonth() + 1);
27-
expect(deadline.value.year()).to.be.equal(date.getFullYear());
24+
25+
// avoid SYSTEM and UTC differences
26+
const networkTimeStamp = (new Date()).getTime();
27+
const timestampLocal = LocalDateTime.ofInstant(Instant.ofEpochMilli(networkTimeStamp), ZoneId.SYSTEM);
28+
const reproducedDate = timestampLocal.plus(2, ChronoUnit.HOURS);
29+
30+
expect(deadline.value.dayOfMonth()).to.be.equal(reproducedDate.dayOfMonth());
31+
expect(deadline.value.monthValue()).to.be.equal(reproducedDate.monthValue());
32+
expect(deadline.value.year()).to.be.equal(reproducedDate.year());
2833
});
2934

3035
it('should throw error deadline smaller than timeStamp', () => {

0 commit comments

Comments
 (0)