Skip to content

Commit

Permalink
Merge branch 'master' into ap-publish-v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mttrbrts committed May 27, 2022
2 parents 7f1ce56 + bea3ed6 commit a37053b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/concerto-core/lib/datetimeutil.js
Expand Up @@ -35,6 +35,9 @@ function setCurrentTime(currentTime, utcOffset) {
// Default UTC offset to local time
const utcOffsetResolved = typeof utcOffset === 'number' ? utcOffset : dayjs().utcOffset();
const currentTimeUTC = currentTime ? dayjs.utc(currentTime) : dayjs().utc();
if (!currentTimeUTC.isValid()) {
throw new Error(`Current time '${currentTime}' is not in standard UTC format`);
}
const currentTimeResolved = currentTimeUTC.utcOffset(utcOffsetResolved);
if (!currentTimeResolved.isValid()) {
throw new Error(`Cannot set current time to '${currentTime}' with UTC offset '${utcOffset}'`);
Expand Down
5 changes: 4 additions & 1 deletion packages/concerto-core/test/datetimeutil.js
Expand Up @@ -32,7 +32,10 @@ describe('Initialize current time', () => {
return currentTime.format().should.equal('1970-01-01T00:00:00+05:00');
});
it('Should fail for a non-well-formed date/time', function () {
return (() => DateTimeUtil.setCurrentTime('foobar')).should.throw('Cannot set current time to \'foobar\' with UTC offset \'undefined\'');
return (() => DateTimeUtil.setCurrentTime('foobar')).should.throw('Current time \'foobar\' is not in standard UTC format');
});
it('Should fail for an invalid UTC offset', function () {
return (() => DateTimeUtil.setCurrentTime('1970-01-01T00:00:00+05:00',999999999999)).should.throw('Cannot set current time to \'1970-01-01T00:00:00+05:00\' with UTC offset \'999999999999\'');
});
it('Should not fail when currentTime is null', function () {
const { currentTime } = DateTimeUtil.setCurrentTime(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-util/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a37053b

Please sign in to comment.