Skip to content

Commit

Permalink
luxon timezone correction for tasmania (#1062)
Browse files Browse the repository at this point in the history
* luxon timezone correction for tasmania

* updated fix for Tasmania datetime

---------

Co-authored-by: Gabriel Fosse <[email protected]>
  • Loading branch information
majesticio and Gabriel Fosse authored Oct 11, 2023
1 parent d12a33e commit 88bd645
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/adapters/tasmania.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import got from 'got';

export const name = 'tasmania';

export function fetchData (source, cb) {
export function fetchData(source, cb) {
got(source.url, { timeout: { request: REQUEST_TIMEOUT } }).then(
(response) => {
try {
Expand All @@ -34,19 +34,21 @@ export function fetchData (source, cb) {

const formatData = function (data, source) {
const parseDate = function (string) {
const date = DateTime.fromFormat(
string.trim(),
'HHmmss',
{ zone: 'Australia/Hobart' }
);
const now = DateTime.now().setZone('Australia/Tasmania');

const hours = parseInt(string.substring(0, 2), 10);
const minutes = parseInt(string.substring(2, 4), 10);
const seconds = parseInt(string.substring(4, 6), 10);

const date = now.set({ hour: hours, minute: minutes, second: seconds });

if (!date.isValid) {
throw new Error('Invalid date format');
}

return {
utc: date.toUTC().toISO({ suppressMilliseconds: true }),
local: date.toISO({ suppressMilliseconds: true }),
utc: date.toUTC().toFormat("yyyy-MM-dd'T'HH:mm:ssZZ"),
local: date.toFormat("yyyy-MM-dd'T'HH:mm:ssZZ"),
};
};

Expand Down

0 comments on commit 88bd645

Please sign in to comment.