hubot-nextbus 2.0.0 → 2.0.2

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.
@@ -19,7 +19,7 @@ jobs:
19
19
  node-version: ${{ matrix.node-version }}
20
20
  - name: npm install, build, and test
21
21
  run: |
22
- npm install
22
+ npm ci
23
23
  npm run build --if-present
24
24
  npm test
25
25
  env:
package/README.md CHANGED
@@ -32,11 +32,11 @@ Returns the next bus for the nearest stop.
32
32
  ```
33
33
  user> hubot nextbus
34
34
  hubot> Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
35
- 7:01:09 #50 - CHARLOTTE WALMART in a minute
36
- 7:15:49 #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes
37
- 7:16:09 #50 - CHARLOTTE WALMART in 16 minutes
38
- 7:31:09 #50 - CHARLOTTE WALMART in 31 minutes
39
- 7:35:49 #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes
35
+ 7:01 AM #50 - CHARLOTTE WALMART in a minute
36
+ 7:15 AM #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes
37
+ 7:16 AM #50 - CHARLOTTE WALMART in 16 minutes
38
+ 7:31 AM #50 - CHARLOTTE WALMART in 31 minutes
39
+ 7:35 AM #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes
40
40
  ```
41
41
 
42
42
  ### `hubot nextbus stops`
@@ -58,11 +58,9 @@ hubot> - [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
58
58
  Returns the next bus for a given stop ID.
59
59
 
60
60
  ```
61
- user> hubot nextbus stop 5AVCHUNM
62
- hubot> Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
63
- 7:01:09 #50 - CHARLOTTE WALMART in a minute
64
- 7:15:49 #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes
65
- 7:16:09 #50 - CHARLOTTE WALMART in 16 minutes
66
- 7:31:09 #50 - CHARLOTTE WALMART in 31 minutes
67
- 7:35:49 #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes
61
+ user> hubot nextbus stop PORGRENN
62
+ hubot> Upcoming Trips for [PORGRENN] PORTER RD & GREENWOOD AVE NB
63
+ 10:34 PM #4 - INGLEWOOD in 25 minutes
64
+ 11:34 PM #4 - INGLEWOOD in an hour
65
+ 12:32 AM #4 - INGLEWOOD in 2 hours
68
66
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hubot-nextbus",
3
3
  "description": "Shows when the next transit vehicle will arrive at a particular stop.",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "author": "Stephen Yeargin <stephen@yearg.in>",
6
6
  "homepage": "https://github.com/transitnownash/hubot-nextbus",
7
7
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "husky": "^8.0.1",
31
31
  "mocha": "^10.0.0",
32
32
  "nock": "^13.2.9",
33
- "release-it": "^15.2.0",
33
+ "release-it": "^15.4.2",
34
34
  "sinon": "^14.0.0",
35
35
  "sinon-chai": "^3.7.0"
36
36
  },
@@ -42,6 +42,6 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "ascii-table": "^0.0.9",
45
- "moment-timezone": "^0.5.34"
45
+ "moment": "^2.29.4"
46
46
  }
47
47
  }
@@ -14,7 +14,7 @@
14
14
  # Author:
15
15
  # stephenyeargin
16
16
 
17
- moment = require('moment-timezone')
17
+ moment = require('moment')
18
18
  AsciiTable = require('ascii-table')
19
19
  baseURL = process.env.HUBOT_NEXTBUS_BASE_URL || 'https://gtfs.transitnownash.org'
20
20
  latlon = process.env.HUBOT_NEXTBUS_LAT_LON
@@ -48,9 +48,12 @@ module.exports = (robot) ->
48
48
  # Override timezone for moment() calls
49
49
  process.env.TZ = agencies.data[0].agency_timezone
50
50
  robot.logger.debug process.env.TZ
51
-
51
+ robot.logger.debug 'Current Time:', moment()
52
52
  getAPIResponse "stops/#{stop_id}/trips.json?per_page=2000", msg, (trips) ->
53
- nextTrips = trips.data.filter((i) => moment(moment().toISOString().split('T')[0] + ' ' + i.stop_times[0].arrival_time.trim().padStart(8, '0')).isAfter(moment(), 'second'))
53
+ nextTrips = trips.data.filter((trip) =>
54
+ tripTime = formatTripTimeAsMoment(trip.stop_times[0].arrival_time)
55
+ return tripTime.isAfter(moment(), 'second')
56
+ )
54
57
  robot.logger.debug nextTrips
55
58
  if nextTrips.length == 0
56
59
  return msg.send "The last bus has already run for today."
@@ -59,11 +62,19 @@ module.exports = (robot) ->
59
62
  stop = nextTrips[0].stop_times[0].stop
60
63
  msg.send "Upcoming Trips for [#{stop.stop_gid}] #{stop.stop_name}"
61
64
  for trip in nextTrips.slice(0, 5)
62
- time = moment(moment().toISOString().split('T')[0] + ' ' + trip.stop_times[0].arrival_time.trim().padStart(8, '0'));
63
- table.addRow [trip.stop_times[0].arrival_time, "##{trip.route_gid} - #{trip.trip_headsign}", time.fromNow()]
65
+ tripTime = formatTripTimeAsMoment(trip.stop_times[0].arrival_time)
66
+ table.addRow [formatTripTimeAsMoment(trip.stop_times[0].arrival_time).format('LT'), "##{trip.route_gid} - #{trip.trip_headsign}", tripTime.fromNow()]
64
67
  table.removeBorder()
65
68
  msg.send table.toString()
66
69
 
70
+ formatTripTimeAsMoment = (timeStr) ->
71
+ if RegExp('^2[4-9]:').test(timeStr)
72
+ timeStr = (parseInt(timeStr.substr(0,2), 10) - 24) + timeStr.substr(2,8)
73
+ tripTime = moment(moment().format('YYYY-MM-DD') + ' ' + timeStr.padStart(8, '0')).add(1, 'days')
74
+ else
75
+ tripTime = moment(moment().format('YYYY-MM-DD') + ' ' + timeStr.trim().padStart(8, '0'))
76
+ return tripTime
77
+
67
78
  getAPIResponse = (path, msg, cb) ->
68
79
  url = "#{baseURL}/#{path}"
69
80
  robot.logger.debug url