mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
added timestamps to app console logs
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { describe, expect, test } from "bun:test";
|
||||||
import { Perf, isBlob, ucFirst } from "../../src/core/utils";
|
import { Perf, datetimeStringUTC, isBlob, ucFirst } from "../../src/core/utils";
|
||||||
import * as utils from "../../src/core/utils";
|
import * as utils from "../../src/core/utils";
|
||||||
|
|
||||||
async function wait(ms: number) {
|
async function wait(ms: number) {
|
||||||
@@ -245,4 +245,14 @@ describe("Core Utils", async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("dates", () => {
|
||||||
|
test.only("formats local time", () => {
|
||||||
|
expect(utils.datetimeStringUTC("2025-02-21T16:48:25.841Z")).toBe("2025-02-21 16:48:25");
|
||||||
|
console.log(utils.datetimeStringUTC(new Date()));
|
||||||
|
console.log(utils.datetimeStringUTC());
|
||||||
|
console.log(new Date());
|
||||||
|
console.log("timezone", Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,4 +11,21 @@ declare module "dayjs" {
|
|||||||
|
|
||||||
dayjs.extend(weekOfYear);
|
dayjs.extend(weekOfYear);
|
||||||
|
|
||||||
|
export function datetimeStringLocal(dateOrString?: string | Date | undefined): string {
|
||||||
|
return dayjs(dateOrString).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function datetimeStringUTC(dateOrString?: string | Date | undefined): string {
|
||||||
|
const date = dateOrString ? new Date(dateOrString) : new Date();
|
||||||
|
return date.toISOString().replace("T", " ").split(".")[0]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTimezoneOffset(): number {
|
||||||
|
return new Date().getTimezoneOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTimezone(): string {
|
||||||
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
}
|
||||||
|
|
||||||
export { dayjs };
|
export { dayjs };
|
||||||
|
|||||||
@@ -2,7 +2,15 @@
|
|||||||
|
|
||||||
import type { App } from "App";
|
import type { App } from "App";
|
||||||
import { tbValidator as tb } from "core";
|
import { tbValidator as tb } from "core";
|
||||||
import { StringEnum, Type, TypeInvalidError } from "core/utils";
|
import {
|
||||||
|
StringEnum,
|
||||||
|
Type,
|
||||||
|
TypeInvalidError,
|
||||||
|
datetimeStringLocal,
|
||||||
|
datetimeStringUTC,
|
||||||
|
getTimezone,
|
||||||
|
getTimezoneOffset
|
||||||
|
} from "core/utils";
|
||||||
import { getRuntimeKey } from "core/utils";
|
import { getRuntimeKey } from "core/utils";
|
||||||
import type { Context, Hono } from "hono";
|
import type { Context, Hono } from "hono";
|
||||||
import { Controller } from "modules/Controller";
|
import { Controller } from "modules/Controller";
|
||||||
@@ -273,7 +281,13 @@ export class SystemController extends Controller {
|
|||||||
hono.get("/info", (c) =>
|
hono.get("/info", (c) =>
|
||||||
c.json({
|
c.json({
|
||||||
version: c.get("app")?.version(),
|
version: c.get("app")?.version(),
|
||||||
runtime: getRuntimeKey()
|
runtime: getRuntimeKey(),
|
||||||
|
timezone: {
|
||||||
|
name: getTimezone(),
|
||||||
|
offset: getTimezoneOffset(),
|
||||||
|
local: datetimeStringLocal(),
|
||||||
|
utc: datetimeStringUTC()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user