Skip to content

Commit 7fd92da

Browse files
committed
SImplify xcurrenttime
1 parent 94e4b06 commit 7fd92da

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

dist/mc-wa-sqlite-async.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/wa-sqlite-async-dynamic-main.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/wa-sqlite-async.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/FacadeVFS.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -233,29 +233,25 @@ export class FacadeVFS extends VFS.Base {
233233
return nByte;
234234
}
235235

236-
/**
236+
/**
237237
* Gets the current time as milliseconds since Unix epoch
238238
* @param {number} pVfs pointer to the VFS
239239
* @param {number} pTime pointer to write the time value
240240
* @returns {number} SQLite error code
241241
*/
242-
xCurrentTimeInt64(pVfs, pTime) {
243-
// Create a DataView to write the current time
244-
const timeView = this.#makeTypedDataView('BigInt64', pTime);
245-
246-
// Exact copy of SQLite's calculation:
247-
// static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
248-
// *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
249-
const seconds = BigInt(Math.floor(Date.now() / 1000));
250-
const microseconds = BigInt(Date.now() % 1000) * 1000n;
251-
252-
const value = UNIX_EPOCH + (1000n * seconds) + (microseconds / 1000n);
253-
254-
// Write the time value to the pointer location
255-
timeView.setBigInt64(0, value, true);
256-
257-
return VFS.SQLITE_OK;
258-
}
242+
xCurrentTimeInt64(pVfs, pTime) {
243+
// Create a DataView to write the current time
244+
const timeView = this.#makeTypedDataView('BigInt64', pTime);
245+
246+
const currentTime = BigInt(Date.now());
247+
// Convert the current time to milliseconds since Unix epoch
248+
const value = UNIX_EPOCH + currentTime;
249+
250+
// Write the time value to the pointer location
251+
timeView.setBigInt64(0, value, true);
252+
253+
return VFS.SQLITE_OK;
254+
}
259255

260256
/**
261257
* @param {number} pVfs

0 commit comments

Comments
 (0)