@transportme/load-ptv-gtfs 1.3.10 → 1.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CALENDAR_DATES } from '../constants.mjs'
|
|
2
|
-
import { parseDate, toGTFSDate } from '../utils.mjs'
|
|
3
2
|
import GTFSCalendarDate from './GTFSCalendarDate.mjs'
|
|
3
|
+
import { dateUtils } from '@transportme/transportvic-utils'
|
|
4
4
|
|
|
5
5
|
export default class GTFSCalendar {
|
|
6
6
|
|
|
@@ -27,8 +27,8 @@ export default class GTFSCalendar {
|
|
|
27
27
|
constructor({ id, daysOfWeek, startDay, endDay }, calendarDates = []) {
|
|
28
28
|
this.id = id
|
|
29
29
|
this.daysOfWeek = daysOfWeek.map(day => day === '1')
|
|
30
|
-
this.startDay = parseDate(startDay)
|
|
31
|
-
this.endDay = parseDate(endDay)
|
|
30
|
+
this.startDay = dateUtils.parseDate(startDay)
|
|
31
|
+
this.endDay = dateUtils.parseDate(endDay)
|
|
32
32
|
|
|
33
33
|
for (let date of calendarDates) {
|
|
34
34
|
if (date.type === CALENDAR_DATES.ADDED) this.#operationDays.push(date.date)
|
|
@@ -57,7 +57,7 @@ export default class GTFSCalendar {
|
|
|
57
57
|
* @returns {string[]} A string array of GTFS formatted dates
|
|
58
58
|
*/
|
|
59
59
|
getOperationDays() {
|
|
60
|
-
return this.#operationDays.sort((a, b) => a - b).map(day => toGTFSDate(day)).filter((date, i, arr) => i === 0 || arr[i - 1] != date)
|
|
60
|
+
return this.#operationDays.sort((a, b) => a - b).map(day => dateUtils.toGTFSDate(day)).filter((date, i, arr) => i === 0 || arr[i - 1] != date)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dateUtils } from '@transportme/transportvic-utils'
|
|
2
2
|
|
|
3
3
|
export default class GTFSCalendarDate {
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ export default class GTFSCalendarDate {
|
|
|
8
8
|
|
|
9
9
|
constructor({ id, date, type }) {
|
|
10
10
|
this.id = id
|
|
11
|
-
this.date = parseDate(date)
|
|
11
|
+
this.date = dateUtils.parseDate(date)
|
|
12
12
|
this.type = type
|
|
13
13
|
}
|
|
14
14
|
|
package/lib/utils.mjs
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import { DateTime } from 'luxon'
|
|
2
|
-
import { TIMEZONES } from './constants.mjs'
|
|
3
|
-
|
|
4
|
-
// Note: Need to allow for SA time as PTV does not handle cross border times well... or at all
|
|
5
|
-
export function parseDate(date) {
|
|
6
|
-
return DateTime.fromFormat(date, 'yyyyMMdd', { zone: TIMEZONES.melbourne })
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function toGTFSDate(date) {
|
|
10
|
-
return date.toFormat('yyyyMMdd')
|
|
11
|
-
}
|
|
12
|
-
|
|
13
1
|
export function minutesPastMidnightToHHMM(time) {
|
|
14
2
|
let hours = Math.floor(time / 60)
|
|
15
3
|
let min = time % 60
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transportme/load-ptv-gtfs",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@transportme/database": "^1.0.27",
|
|
13
|
-
"@transportme/transportvic-utils": "^1.0.
|
|
13
|
+
"@transportme/transportvic-utils": "^1.0.4",
|
|
14
14
|
"@turf/boolean-point-in-polygon": "^7.1.0",
|
|
15
15
|
"adm-zip": "^0.5.14",
|
|
16
16
|
"async": "^3.2.6",
|
|
@@ -6,7 +6,7 @@ import GTFSCalendarDate from '../lib/gtfs-parser/GTFSCalendarDate.mjs'
|
|
|
6
6
|
import path from 'path'
|
|
7
7
|
import url from 'url'
|
|
8
8
|
import { CALENDAR_DATES } from '../lib/constants.mjs'
|
|
9
|
-
import {
|
|
9
|
+
import { dateUtils } from '@transportme/transportvic-utils'
|
|
10
10
|
|
|
11
11
|
const __filename = url.fileURLToPath(import.meta.url)
|
|
12
12
|
const __dirname = path.dirname(__filename)
|
|
@@ -151,12 +151,12 @@ describe('The GTFSCalendarDatesReader class', () => {
|
|
|
151
151
|
|
|
152
152
|
let date = await reader.getNextEntity()
|
|
153
153
|
expect(date.id).to.equal('T3_2')
|
|
154
|
-
expect(toGTFSDate(date.date)).to.equal('20250126')
|
|
154
|
+
expect(dateUtils.toGTFSDate(date.date)).to.equal('20250126')
|
|
155
155
|
expect(date.type).to.equal(CALENDAR_DATES.REMOVED)
|
|
156
156
|
|
|
157
157
|
let date2 = await reader.getNextEntity()
|
|
158
158
|
expect(date2.id).to.equal('T5_2')
|
|
159
|
-
expect(toGTFSDate(date2.date)).to.equal('20241225')
|
|
159
|
+
expect(dateUtils.toGTFSDate(date2.date)).to.equal('20241225')
|
|
160
160
|
expect(date2.type).to.equal(CALENDAR_DATES.REMOVED)
|
|
161
161
|
})
|
|
162
162
|
})
|
package/test/utils-test.mjs
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai'
|
|
2
|
-
import { hhmmToMinutesPastMidnight
|
|
2
|
+
import { hhmmToMinutesPastMidnight } from '../lib/utils.mjs'
|
|
3
3
|
|
|
4
4
|
describe('The utils class', () => {
|
|
5
|
-
describe('The parseDate function', () => {
|
|
6
|
-
it('Should convert a GTFS date to a Melbourne timezoned date', () => {
|
|
7
|
-
expect(parseDate('20241122').toUTC().toISO()).to.equal('2024-11-21T13:00:00.000Z')
|
|
8
|
-
})
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
describe('The toGTFSDate function', () => {
|
|
13
|
-
it('Should convert a Luxon date back into a GTFS date', () => {
|
|
14
|
-
let date = parseDate('20241122')
|
|
15
|
-
expect(toGTFSDate(date.plus({ day: 3 }))).to.equal('20241125')
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
5
|
describe('The hhmmToMinutesPastMidnight function', () => {
|
|
20
6
|
it('Should convert a HH:MM timestamp into the minutes past midnight', () => {
|
|
21
7
|
expect(hhmmToMinutesPastMidnight('06:05')).to.equal(6 * 60 + 5)
|