// 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`; } // How many in-game hours there are from `totalHours` to the same moment one // calendar month later. Months differ in length, so a forecast that speaks of // "the next month" should not assume a fixed 30 days. export function hoursInNextMonth(totalHours) { const date = new Date(unixTime(totalHours) * 1000); const later = new Date(date.getTime()); later.setUTCMonth(later.getUTCMonth() + 1); return Math.round((later.getTime() - date.getTime()) / (UNIX_SECONDS_PER_HOUR * 1000)); }