Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wasm): correct ms to s conversion #31

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
});