i got the same result (the correct time for Latvia) when using the following EcmaScript6 Source
in 0 A.D.
In the case of 0 A.D. that is used here, the game's source code include JavaScript code written using ES6 syntax. This code would be executed by a JavaScript engine that is bundled with the game's runtime environment. BTW there is no support for console.log()
const formatTime = (date, timeZone) => {
const options = {
hour: "numeric",
minute: "numeric",
hour12: true,
timeZone: timeZone,
};
return date.toLocaleTimeString("en-US", options);
};
const getNextHalfHour = (inNextFullMinute) => {
const now = new Date();
const minutes = now.getMinutes();
if (!inNextFullMinute && isNaN(inNextFullMinute)) inNextFullMinute = 30;
else inNextFullMinute = parseInt(inNextFullMinute);
const roundedMinutes =
Math.ceil(minutes / inNextFullMinute) * inNextFullMinute;
const nextHalfHour = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
now.getHours(),
roundedMinutes,
0,
);
if (roundedMinutes === 60) {
nextHalfHour.setHours(now.getHours() + 1);
nextHalfHour.setMinutes(0);
}
return nextHalfHour;
};
const nextHalfHour = getNextHalfHour();
console.log(
"Europe/London:",
formatTime(
new Date(nextHalfHour.getTime() + 1 * 60 * 60 * 1000),
"Europe/London",
),
);
console.log(
"America/Los_Angeles:",
formatTime(
new Date(nextHalfHour.getTime() + 1 * 60 * 60 * 1000),
"America/Los_Angeles",
),
);
These two time zones (Europe/London
, America/Los_Angeles
)
have a significant time difference.
If i write FunPlanat/moon
instead America/Los_Angeles
i still get the same result and no errors.
i wonder that i cannot provocate an error here and that the results always the same correct result for Lativa
.
The formatTime function in ES6 is a custom function that takes a Date object and a time zone identifier as inputs, and returns a formatted string representation of the time in the specified time zone.
If this source correct? Or how i could fix that if not?
i was reading here about formatTime function
:
- convert date time to utc format
- https://www.tutorialspoint.com/display-the-asian-and-american-date-time-with-date-object-in-javascript
- How do I format a date in JavaScript?
This is the complete source snippet that i using in https://github.com/sl5net/autocivP/commit/dd65aafff2c95d60014da8423a192cdcf68f4c70
formatTime(new Date('2023-07-08'), 'Asia/Kolkata');
// gives same result like formatTime(new Date('2023-07-08'), 'moonShip');
const tBerlinLondonSwedenDenmark = formatTime(nextHalfHour, "Europe/London");
// const tSweden = formatTime(new Date(nextHalfHour.getTime() + (1 * 60 * 60 * 1000)), 'Europe/Stockholm');
const Latvia = formatTime(
new Date(nextHalfHour.getTime() + 1 * 60 * 60 * 1000),
"Europe/London",
);
const RioGrandeDoSulBrasilien = formatTime(
new Date(nextHalfHour.getTime() - 5 * 60 * 60 * 1000),
"Europe/London",
);
const tGreece = formatTime(
new Date(nextHalfHour.getTime() + 1 * 60 * 60 * 1000),
"Europe/Athens",
);
const Asia_Kolkata = formatTime(
new Date(nextHalfHour.getTime() + 3.5 * 60 * 60 * 1000),
"Asia/Kolkata",
);
const USA_ET = formatTime(
new Date(nextHalfHour.getTime() - 6 * 60 * 60 * 1000),
"America/New_York",
);
const USA_Los_Angeles = formatTime(
new Date(nextHalfHour.getTime() - 9 * 60 * 60 * 1000),
"America/Los_Angeles",
);
const USA_Chicago = formatTime(
new Date(nextHalfHour.getTime() - 7 * 60 * 60 * 1000),
"America/Los_Angeles",
);