Skip to content

Commit

Permalink
fix(rc): Fix Version update time parsing failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumaramba committed Nov 13, 2020
1 parent 13afb20 commit 7d41cf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,12 @@ class VersionImpl implements Version {
// as UTC date strings. If a developer uses a previously obtained template with UTC timestamps
// we could still validate it below.
if (typeof version.updateTime !== 'undefined') {
if (!validator.isISODateString(version.updateTime) &&
!validator.isUTCDateString(version.updateTime)) {
if (!this.isValidTimestamp(version.updateTime)) {
throw new FirebaseRemoteConfigError(
'invalid-argument',
'Version update time must be a valid date string');
}
if (validator.isISODateString(version.updateTime)) {
// timestamps in output `Version` obtained from the API should be in UTC.
this.updateTime = new Date(version.updateTime).toUTCString();
}
this.updateTime = new Date(version.updateTime).toUTCString();
}
}

Expand All @@ -394,4 +390,8 @@ class VersionImpl implements Version {
updateTime: this.updateTime,
}
}

private isValidTimestamp(timestamp: string): boolean {
return validator.isNonEmptyString(timestamp) && (new Date(timestamp)).getTime() > 0;
}
}
6 changes: 3 additions & 3 deletions test/unit/remote-config/remote-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('RemoteConfig', () => {
email: '[email protected]'
},
description: 'production version',
updateTime: '2020-06-15T16:45:03.000Z'
updateTime: '2020-06-15T16:45:03.541527Z'
};

const REMOTE_CONFIG_RESPONSE: {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('RemoteConfig', () => {
versions: [
{
versionNumber: '78',
updateTime: '2020-05-07T18:46:09.495Z',
updateTime: '2020-05-07T18:46:09.495234Z',
updateUser: {
email: '[email protected]',
imageUrl: 'https://photo.jpg'
Expand All @@ -135,7 +135,7 @@ describe('RemoteConfig', () => {
},
{
versionNumber: '77',
updateTime: '2020-05-07T18:44:41.555Z',
updateTime: '2020-05-07T18:44:41.555123Z',
updateUser: {
email: '[email protected]',
imageUrl: 'https://photo.jpg'
Expand Down

0 comments on commit 7d41cf5

Please sign in to comment.