Skip to content

Commit

Permalink
fix(wasm): correct ms to s conversion (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Aug 17, 2023
1 parent 14ceeb5 commit 38557ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/snippets/deno_cache_dir-bd7d6e431c0654b5/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export function atomic_write_file(path, bytes) {
export function modified_time(path) {
try {
const stat = Deno.lstatSync(path);
const msToS = 1000;
return stat.mtime.getTime() * msToS;
return msToS(stat.mtime.getTime());
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
return undefined;
Expand All @@ -79,6 +78,9 @@ export function is_file(path) {
}

export function time_now() {
const msToS = 1000;
return Date.now() * msToS;
return msToS(Date.now());
}

function msToS(ms) {
return Math.round(ms / 1000);
}
10 changes: 6 additions & 4 deletions rs_lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export function atomic_write_file(path, bytes) {
export function modified_time(path) {
try {
const stat = Deno.lstatSync(path);
const msToS = 1000;
return stat.mtime.getTime() * msToS;
return msToS(stat.mtime.getTime());
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
return undefined;
Expand All @@ -79,6 +78,9 @@ export function is_file(path) {
}

export function time_now() {
const msToS = 1000;
return Date.now() * msToS;
return msToS(Date.now());
}

function msToS(ms) {
return Math.round(ms / 1000);
}
12 changes: 12 additions & 0 deletions rs_lib/fs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

import { time_now } from "./fs.js";

Deno.test("gets correct time", () => {
const seconds = time_now();
const expected = Math.round(Date.now() / 1000);
if (expected != seconds) {
console.error("Values:", expected, seconds);
throw new Error("Not equal");
}
});

0 comments on commit 38557ff

Please sign in to comment.