Skip to content

Commit d5ac13e

Browse files
committed
Fix lastSyncedAt.
1 parent 97f4521 commit d5ac13e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/powersync/lib/src/database/powersync_db_mixin.dart

+6-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
129129
final hasSynced = timestamp != null;
130130

131131
if (hasSynced != currentStatus.hasSynced) {
132-
final lastSyncedAt = timestamp == null ? null : DateTime.parse(timestamp);
132+
final lastSyncedAt =
133+
timestamp == null ? null : DateTime.parse('${timestamp}Z').toLocal();
133134
final status =
134135
SyncStatus(hasSynced: hasSynced, lastSyncedAt: lastSyncedAt);
135136
setStatus(status);
@@ -157,7 +158,8 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
157158
// The previous values of hasSynced should be preserved here.
158159
hasSynced: status.lastSyncedAt != null
159160
? true
160-
: status.hasSynced ?? currentStatus.hasSynced);
161+
: status.hasSynced ?? currentStatus.hasSynced,
162+
lastSyncedAt: status.lastSyncedAt ?? currentStatus.lastSyncedAt);
161163
statusStreamController.add(currentStatus);
162164
}
163165
}
@@ -260,7 +262,8 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
260262
await tx.execute('select powersync_clear(?)', [clearLocal ? 1 : 0]);
261263
});
262264
// The data has been deleted - reset these
263-
setStatus(SyncStatus(lastSyncedAt: null, hasSynced: false));
265+
currentStatus = SyncStatus(lastSyncedAt: null, hasSynced: false);
266+
statusStreamController.add(currentStatus);
264267
}
265268

266269
@Deprecated('Use [disconnectAndClear] instead.')

0 commit comments

Comments
 (0)