Skip to content

Commit b2f175d

Browse files
majesticioGabriel Fosse
andauthored
fixed datetime errors for tasmania (#1055)
* fixed datetime errors for tasmania * clean up --------- Co-authored-by: Gabriel Fosse <[email protected]>
1 parent 43c2e1c commit b2f175d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/adapters/tasmania.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export function fetchData (source, cb) {
2424
if (data === undefined) {
2525
throw new Error('Failure to parse data.');
2626
}
27-
2827
cb(null, data);
2928
} catch (error) {
3029
cb(error, { message: 'Unknown adapter error.' }, null);
@@ -38,13 +37,19 @@ const formatData = function (data, source) {
3837
const date = DateTime.fromFormat(
3938
string.trim(),
4039
'HHmmss',
41-
'Australia/Hobart'
40+
{ zone: 'Australia/Hobart' }
4241
);
42+
43+
if (!date.isValid) {
44+
throw new Error('Invalid date format');
45+
}
46+
4347
return {
4448
utc: date.toUTC().toISO({ suppressMilliseconds: true }),
4549
local: date.toISO({ suppressMilliseconds: true }),
4650
};
4751
};
52+
4853
// manually retrieved list of station names
4954
// new stations should be checked for naming on this map:
5055
// http://epa.tas.gov.au/_layouts/15/Lightbox.aspx?url=http%3A%2F%2Fepa.tas.gov.au%2FAir%2FLive%2Flatest_air_data_on_map.jpg
@@ -101,15 +106,10 @@ const formatData = function (data, source) {
101106

102107
// loop through the csv rows
103108
for (let k = 0; k < output.length; k++) {
104-
// Station, hhmmss(AEST), PM2.5(ug/m^3), PM10(ug/m^3), lat(deg), long(degE), alt(m), Station name
105109
const value = output[k];
106110
const currentDate = value[1];
107-
108-
// Tasmania stations seem to use hhmmss = 999999 when the station
109-
// is not available. check for and ignore these records
110-
// also check the name matched in the locations list, otherwise this is a new station
111111
const location = stations[value[0]];
112-
if (currentDate === '999999' || location === 'undefined') {
112+
if (currentDate === '999999' || location === undefined) {
113113
continue;
114114
}
115115
const dates = parseDate(currentDate);
@@ -118,7 +118,6 @@ const formatData = function (data, source) {
118118
const lat = value[4];
119119
const lng = value[5];
120120

121-
// base obj for resuse
122121
const baseObj = {
123122
location: location,
124123
city: source.city,
@@ -137,18 +136,17 @@ const formatData = function (data, source) {
137136
date: dates,
138137
};
139138

140-
// PM2.5 entry
141139
const objPM25 = cloneDeep(baseObj);
142140
objPM25.value = parseFloat(pm25);
143141
objPM25.parameter = 'pm25';
144142
measurements.push(objPM25);
145143

146-
// PM10 entry
147144
const objPM10 = cloneDeep(baseObj);
148145
objPM10.value = parseFloat(pm10);
149146
objPM10.parameter = 'pm10';
150147
measurements.push(objPM10);
151148
}
149+
152150
measurements = convertUnits(flatten(measurements));
153151
return {
154152
name: 'unused',

0 commit comments

Comments
 (0)