Drop in replacements for elm/time's's Tasks.
The JavaScript runner has these tasks builtin by default. If needed they can be overridden like so:
NOTE: The custom examples are the same as the built-in implementations.
import * as ConcurrentTask from "@andrewmacmurray/elm-concurrent-task"
ConcurrentTask.register({
tasks: {},
ports: app.ports,
builtins: {
timeNow: customTimeNow,
timeZoneOffset: customTimeZoneOffset,
timeZoneName: customTimeZoneName,
}
});
function customTimeNow(): number {
return Date.now()
}
function customTimeZoneOffset(): number {
return -new Date().getTimezoneOffset();
}
function customTimeZoneName(): string | number {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
} catch (e) {
return new Date().getTimezoneOffset();
}
}Produce a Zone based on the current UTC offset.
A direct replacement for elm/time's Time.here.
Use Intl.DateTimeFormat().resolvedOptions().timeZone to try to get names like Europe/Moscow or America/Havana.
A direct replacement for elm/time's Time.getZoneName.
Get the POSIX time at the moment when this task is run.
A direct replacement for
elm/time'sTime.now.