Skip to content

Commit a1a7e79

Browse files
authored
Merge pull request #3338 from numbersprotocol/copilot/fix-3336
Fix Incorrect Asset Date When Viewing Restored Data Offline
2 parents fde6f9d + 63d032f commit a1a7e79

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
1. Fix incorrect asset date display when viewing restored data offline [#3336](https://github.com/numbersprotocol/capture-lite/issues/3336)
1213
1. Add missing NSLocationAlwaysAndWhenInUseUsageDescription purpose string in Info.plist for iOS
1314

1415
## [0.101.1] - 2025-03-21

src/app/shared/repositories/proof/proof.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,12 @@ export class Proof {
5858

5959
/**
6060
* Used to sort the assets in the VERIFIED tab either by timestamp or uploadedAt (if available).
61+
* Since timestamp getter now ensures values are always in milliseconds, we don't need
62+
* to perform the seconds-to-milliseconds conversion here.
6163
*/
6264
get uploadedAtOrTimestamp() {
63-
const MILLISECONDS_PER_SECOND = 1000;
64-
const LENGTH_IN_MILLISECONDS = 13;
65-
66-
// convert timestamp to milliseconds if needed
67-
const proofTimestampInMilliseconds =
68-
this.timestamp.toString().length === LENGTH_IN_MILLISECONDS
69-
? this.timestamp
70-
: this.timestamp * MILLISECONDS_PER_SECOND;
71-
7265
const serverTimestampInMilliseconds = Date.parse(this.uploadedAt ?? '');
73-
return serverTimestampInMilliseconds || proofTimestampInMilliseconds;
66+
return serverTimestampInMilliseconds || this.timestamp;
7467
}
7568

7669
/**
@@ -80,10 +73,21 @@ export class Proof {
8073
* Note: After restoring or syncing with the backend assets, the timestamp will be in seconds.
8174
* For more details, refer to https://github.com/numbersprotocol/storage-backend/issues/976
8275
*
83-
* Note: Milliseconds are 13 digits long, while seconds are 10 digits long.
76+
* Note: Milliseconds are typically 13 digits long (after 2001), while seconds are
77+
* typically 10 digits long.
78+
* We use a threshold-based approach to detect and convert between these formats.
79+
*
80+
* This getter ensures timestamps are always returned in milliseconds regardless of
81+
* how they're stored (seconds or milliseconds).
8482
*/
8583
get timestamp() {
86-
return this.truth.timestamp;
84+
const MILLISECONDS_PER_SECOND = 1000;
85+
const MILLISECONDS_THRESHOLD = 10000000000; // 10^10, timestamps after March 2001
86+
87+
// Convert to milliseconds if the timestamp is in seconds
88+
return this.truth.timestamp > MILLISECONDS_THRESHOLD
89+
? this.truth.timestamp
90+
: this.truth.timestamp * MILLISECONDS_PER_SECOND;
8791
}
8892

8993
get deviceName() {

0 commit comments

Comments
 (0)