Skip to content

Commit e540ddd

Browse files
committed
fix(rc): Fix Version update time parsing failure
1 parent 13afb20 commit e540ddd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/remote-config/remote-config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,12 @@ class VersionImpl implements Version {
366366
// as UTC date strings. If a developer uses a previously obtained template with UTC timestamps
367367
// we could still validate it below.
368368
if (typeof version.updateTime !== 'undefined') {
369-
if (!validator.isISODateString(version.updateTime) &&
370-
!validator.isUTCDateString(version.updateTime)) {
369+
if (!this.isValidTimestamp(version.updateTime)) {
371370
throw new FirebaseRemoteConfigError(
372371
'invalid-argument',
373372
'Version update time must be a valid date string');
374373
}
375-
if (validator.isISODateString(version.updateTime)) {
376-
// timestamps in output `Version` obtained from the API should be in UTC.
377-
this.updateTime = new Date(version.updateTime).toUTCString();
378-
}
374+
this.updateTime = new Date(version.updateTime).toUTCString();
379375
}
380376
}
381377

@@ -394,4 +390,8 @@ class VersionImpl implements Version {
394390
updateTime: this.updateTime,
395391
}
396392
}
393+
394+
private isValidTimestamp(timestamp: string): boolean {
395+
return validator.isNonEmptyString(timestamp) && (new Date(timestamp)).getTime() > 0;
396+
}
397397
}

test/unit/remote-config/remote-config.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('RemoteConfig', () => {
6464
6565
},
6666
description: 'production version',
67-
updateTime: '2020-06-15T16:45:03.000Z'
67+
updateTime: '2020-06-15T16:45:03.541527Z'
6868
};
6969

7070
const REMOTE_CONFIG_RESPONSE: {
@@ -123,7 +123,7 @@ describe('RemoteConfig', () => {
123123
versions: [
124124
{
125125
versionNumber: '78',
126-
updateTime: '2020-05-07T18:46:09.495Z',
126+
updateTime: '2020-05-07T18:46:09.495234Z',
127127
updateUser: {
128128
129129
imageUrl: 'https://photo.jpg'

0 commit comments

Comments
 (0)