Skip to content

Commit

Permalink
Implemented #94 Make the roDateTime.GetTimeZoneOffset() consider `r…
Browse files Browse the repository at this point in the history
…oDeviceInfo.GetTimeZone()`
  • Loading branch information
lvcabral committed Nov 11, 2023
1 parent 1f5f97e commit 3eac3a9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/brsTypes/components/RoDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,16 @@ export class RoDateTime extends BrsComponent implements BrsValue {
args: [],
returns: ValueKind.Int32,
},
impl: (_: Interpreter) => {
const date = new Date(this.markTime);
return new Int32(date.getTimezoneOffset());
impl: (interpreter: Interpreter) => {

// From: https://stackoverflow.com/a/68593283
const getOffset = (timeZone = 'UTC', date = new Date()) => {
const utcDate = new Date(date.toLocaleString('en-US', { timeZone: 'UTC' }));
const tzDate = new Date(date.toLocaleString('en-US', { timeZone: timeZone }));
return (tzDate.getTime() - utcDate.getTime()) / 6e4;
}

return new Int32(-getOffset(interpreter.deviceInfo.get("timeZone")));
},
});

Expand Down

0 comments on commit 3eac3a9

Please sign in to comment.