28 lines
976 B
JavaScript
28 lines
976 B
JavaScript
// Global game clock constants and date formatting, ported from
|
|
// scripts/classes/game_clock.gd. One real second is one in-game hour.
|
|
|
|
export const SECONDS_PER_HOUR = 1.0;
|
|
export const HOURS_PER_DAY = 24;
|
|
export const DAYS_PER_YEAR = 365;
|
|
export const HOURS_PER_YEAR = HOURS_PER_DAY * DAYS_PER_YEAR;
|
|
export const UNIX_SECONDS_PER_HOUR = 3600;
|
|
export const START_UNIX_TIME = 946684800;
|
|
|
|
export const MONTH_NAMES = [
|
|
"January", "February", "March", "April", "May", "June",
|
|
"July", "August", "September", "October", "November", "December",
|
|
];
|
|
|
|
export function unixTime(totalHours) {
|
|
return START_UNIX_TIME + totalHours * UNIX_SECONDS_PER_HOUR;
|
|
}
|
|
|
|
export function dateString(totalHours) {
|
|
const date = new Date(unixTime(totalHours) * 1000);
|
|
const day = date.getUTCDate();
|
|
const month = MONTH_NAMES[date.getUTCMonth()];
|
|
const year = date.getUTCFullYear();
|
|
const hour = date.getUTCHours();
|
|
return `${day} ${month} ${year}, ${String(hour).padStart(2, "0")}:00`;
|
|
}
|