@wmfs/tymly-schedule-plugin 1.5.0 → 1.6.1

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.
@@ -10,7 +10,7 @@ jobs:
10
10
  TZ: "Europe/London"
11
11
  PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/circle_test
12
12
  TIMEOUT: 15000
13
- - image: cimg/postgres:15.1-postgis
13
+ - image: cimg/postgres:15.2-postgis
14
14
  auth:
15
15
  username: $DOCKERHUB_USERNAME
16
16
  password: $DOCKERHUB_PASSWORD
package/.version CHANGED
@@ -1 +1 @@
1
- VERSION=1.5.0
1
+ VERSION=1.6.1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ ## [1.6.1](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.6.0...v1.6.1) (2023-06-07)
2
+
3
+
4
+ ### 🐛 Bug Fixes
5
+
6
+ * better utc handling with consequent test updates ([d15c042](https://github.com/wmfs/tymly-schedule-plugin/commit/d15c042987ebb61fb382eedb057413d718e825ea))
7
+
8
+
9
+ ### 🛠 Builds
10
+
11
+ * **deps-dev:** update dependency [@wmfs](https://github.com/wmfs)/tymly-pg-plugin to v1.283.0 ([3322021](https://github.com/wmfs/tymly-schedule-plugin/commit/332202187f248defb6a68403dec428e9176efdbb))
12
+ * **deps-dev:** update dependency semantic-release to v21.0.3 ([b2da7ba](https://github.com/wmfs/tymly-schedule-plugin/commit/b2da7babde8a45e0d899870ee5b4021c8a662d3b))
13
+ * **deps-dev:** update dependency standard to v17.1.0 ([f7def04](https://github.com/wmfs/tymly-schedule-plugin/commit/f7def04f6abdb127fb0aa6ad02cc7b069480dee9))
14
+
15
+
16
+ ### 📦 Code Refactoring
17
+
18
+ * renamed vars to improve clarity ([4ed331c](https://github.com/wmfs/tymly-schedule-plugin/commit/4ed331c0edbbd3740e72b18961122d2710ce4e39))
19
+
20
+
21
+ ### 🚨 Tests
22
+
23
+ * minor change from let to const for standard ([e81e5de](https://github.com/wmfs/tymly-schedule-plugin/commit/e81e5dec130e9d35ad9460a316a3bce42ea9fcfc))
24
+ * restored tests that were inadvertantly removed ([843e6d5](https://github.com/wmfs/tymly-schedule-plugin/commit/843e6d5e0ddd9e5046e39df8ff068e489e7fdfd7))
25
+
26
+ # [1.6.0](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.5.0...v1.6.0) (2023-06-06)
27
+
28
+
29
+ ### ✨ Features
30
+
31
+ * updated schema for cardscript files ([02156dc](https://github.com/wmfs/tymly-schedule-plugin/commit/02156dc4efbc13795523ed130de1ad3144e932fe))
32
+
33
+
34
+ ### 🐛 Bug Fixes
35
+
36
+ * fixed bug with scheduling an event at a timestamp, to account for timezone offset ([a4b561b](https://github.com/wmfs/tymly-schedule-plugin/commit/a4b561b5592f3bb59b1f1399ac95d87b47b1dc3d))
37
+ * moved moment dep from dev dependencies to main dependencies as serice class uses it ([0d39fca](https://github.com/wmfs/tymly-schedule-plugin/commit/0d39fcad9274c68a04251c98184439d8403b2230))
38
+
39
+
40
+ ### 🛠 Builds
41
+
42
+ * **deps-dev:** update dependency [@semantic-release](https://github.com/semantic-release)/changelog to v6.0.3 ([b36f0c4](https://github.com/wmfs/tymly-schedule-plugin/commit/b36f0c4fbcc3c1d3a5f5c614f74c0640e1196791))
43
+ * **deps-dev:** update dependency [@wmfs](https://github.com/wmfs)/tymly-pg-plugin to v1.277.0 ([1af6de4](https://github.com/wmfs/tymly-schedule-plugin/commit/1af6de41da845a565a656b8facd31874fc1ee6d1))
44
+ * **deps-dev:** update dependency [@wmfs](https://github.com/wmfs)/tymly-pg-plugin to v1.278.0 ([befcf37](https://github.com/wmfs/tymly-schedule-plugin/commit/befcf37d7a756e0ca9a19393c4d1870fc8857e53))
45
+ * **deps-dev:** update dependency [@wmfs](https://github.com/wmfs)/tymly-pg-plugin to v1.282.0 ([a9dc578](https://github.com/wmfs/tymly-schedule-plugin/commit/a9dc5789864b9fab522d7a44d830f4679bb93af8))
46
+ * **deps-dev:** update dependency semantic-release to v20.1.1 ([c825925](https://github.com/wmfs/tymly-schedule-plugin/commit/c8259255193dde8730188686542f8da785f319a0))
47
+ * **deps-dev:** update dependency semantic-release to v20.1.3 ([eb9d5ee](https://github.com/wmfs/tymly-schedule-plugin/commit/eb9d5eec5a10356ffefebb0837800aa7d752cbfe))
48
+ * **deps-dev:** update dependency semantic-release to v21 ([cbe91b5](https://github.com/wmfs/tymly-schedule-plugin/commit/cbe91b5118564c1cbb9f43854a611934efc60289))
49
+
50
+
51
+ ### ⚙️ Continuous Integrations
52
+
53
+ * **circle:** update postgres to 15.2-postgis [sc-19693] ([a7e5b6c](https://github.com/wmfs/tymly-schedule-plugin/commit/a7e5b6cc54612947118887e15647caf62174e172))
54
+
1
55
  # [1.5.0](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.4.0...v1.5.0) (2023-02-17)
2
56
 
3
57
 
@@ -4,19 +4,6 @@
4
4
  "title": "Configure a Scheduled State Machine",
5
5
  "category": "schedule"
6
6
  },
7
- "hooks": {
8
- "afterSubmit": {
9
- "actions": [
10
- {
11
- "type": "Action.PushCard",
12
- "stateMachineName": "schedule_viewScheduledTask_1_0",
13
- "input": {
14
- "key": "$.key"
15
- }
16
- }
17
- ]
18
- }
19
- },
20
7
  "type": "AdaptiveCard",
21
8
  "body": [
22
9
  {
@@ -92,6 +79,19 @@
92
79
  "title": "Submit"
93
80
  }
94
81
  ],
95
- "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
82
+ "hooks": {
83
+ "afterSubmit": {
84
+ "actions": [
85
+ {
86
+ "type": "Action.PushCard",
87
+ "stateMachineName": "schedule_viewScheduledTask_1_0",
88
+ "input": {
89
+ "key": "$.key"
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ "$schema": "https://raw.githubusercontent.com/wmfs/cardscript-schema/master/lib/schema.json",
96
96
  "version": "1.0"
97
97
  }
@@ -31,6 +31,6 @@
31
31
  ]
32
32
  }
33
33
  ],
34
- "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
34
+ "$schema": "https://raw.githubusercontent.com/wmfs/cardscript-schema/master/lib/schema.json",
35
35
  "version": "1.0"
36
36
  }
@@ -143,6 +143,6 @@
143
143
  ]
144
144
  }
145
145
  ],
146
- "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
146
+ "$schema": "https://raw.githubusercontent.com/wmfs/cardscript-schema/master/lib/schema.json",
147
147
  "version": "1.0"
148
148
  }
@@ -1,8 +1,8 @@
1
1
  const INSTIGATING_CLIENT_DOMAIN = 'tymly-schedule-plugin'
2
2
 
3
3
  const nodeSchedule = require('node-schedule')
4
- const ruleToDatetime = require('./utils/rule-to-datetime')
5
- const datetimeToRule = require('./utils/datetime-to-rule')
4
+ const ruleToUTCDateTime = require('./utils/rule-to-datetime')
5
+ const localDateTimeToUTCRule = require('./utils/datetime-to-rule')
6
6
  const { v4: uuidv4 } = require('uuid')
7
7
 
8
8
  class CronService {
@@ -45,7 +45,7 @@ class CronService {
45
45
  if (scheduleType === 'interval') {
46
46
  jobOptions.rule = interval
47
47
  } else if (scheduleType === 'datetime') {
48
- const rule = datetimeToRule(datetime)
48
+ const rule = localDateTimeToUTCRule(datetime)
49
49
 
50
50
  Object
51
51
  .entries(rule)
@@ -58,7 +58,7 @@ class CronService {
58
58
  task.job = nodeSchedule.scheduleJob(
59
59
  jobOptions,
60
60
  () => {
61
- console.log(`Running scheduled state machine ${stateMachineName}`)
61
+ console.log(`Running scheduled state machine ${stateMachineName} at ${new Date()}`)
62
62
  const executionOptions = {
63
63
  instigatingClient: {
64
64
  appName: 'tymly',
@@ -145,7 +145,7 @@ class CronService {
145
145
  config.datetime = null
146
146
  } else if (typeof config.rule === 'object') {
147
147
  config.scheduleType = 'datetime'
148
- config.datetime = ruleToDatetime(config.rule)
148
+ config.datetime = ruleToUTCDateTime(config.rule)
149
149
  config.interval = null
150
150
  }
151
151
 
@@ -219,7 +219,7 @@ class CronService {
219
219
  this.scheduledTasks[key].scheduleType = 'interval'
220
220
  } else if (typeof rule === 'object') {
221
221
  this.scheduledTasks[key].interval = null
222
- this.scheduledTasks[key].datetime = ruleToDatetime(rule)
222
+ this.scheduledTasks[key].datetime = ruleToUTCDateTime(rule)
223
223
  this.scheduledTasks[key].scheduleType = 'datetime'
224
224
  }
225
225
 
@@ -5,6 +5,9 @@ module.exports = function (datetime) {
5
5
  datetime = new Date()
6
6
  }
7
7
 
8
+ // convert local time back to UTC
9
+ datetime = moment(datetime).utc()
10
+
8
11
  return {
9
12
  year: moment(datetime).year(),
10
13
  month: moment(datetime).month(),
@@ -1,6 +1,8 @@
1
+ const moment = require('moment')
2
+
1
3
  module.exports = function (rule = {}) {
2
4
  const now = new Date()
3
- return new Date(
5
+ const date = new Date(
4
6
  isNaN(rule.year) ? now.getFullYear() : rule.year,
5
7
  isNaN(rule.month) ? now.getMonth() : rule.month,
6
8
  isNaN(rule.date) ? now.getDate() : rule.date,
@@ -8,4 +10,8 @@ module.exports = function (rule = {}) {
8
10
  isNaN(rule.minute) ? now.getMinutes() : rule.minute,
9
11
  isNaN(rule.second) ? now.getSeconds() : rule.second
10
12
  )
13
+ // note that rule does not specify a timezone, so we have to assume that
14
+ // the timestamp provided is a local timestamp - as such, we have to convert
15
+ // to UTC
16
+ return moment(date).utc().toDate()
11
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wmfs/tymly-schedule-plugin",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "Provides state machine scheduling for the Tymly framework",
5
5
  "homepage": "https://github.com/wmfs/tymly-schedule-plugin#readme",
6
6
  "author": "West Midlands Fire Service",
@@ -23,14 +23,15 @@
23
23
  "main": "./lib/index.js",
24
24
  "dependencies": {
25
25
  "node-schedule": "2.1.1",
26
- "uuid": "^9.0.0"
26
+ "uuid": "^9.0.0",
27
+ "moment": "2.29.4"
27
28
  },
28
29
  "devDependencies": {
29
- "@semantic-release/changelog": "6.0.2",
30
+ "@semantic-release/changelog": "6.0.3",
30
31
  "@semantic-release/exec": "6.0.3",
31
32
  "@semantic-release/git": "10.0.1",
32
33
  "@wmfs/tymly": "1.242.0",
33
- "@wmfs/tymly-pg-plugin": "1.276.0",
34
+ "@wmfs/tymly-pg-plugin": "1.283.0",
34
35
  "@wmfs/tymly-test-helpers": "1.22.2",
35
36
  "chai": "4.3.7",
36
37
  "codecov": "3.8.3",
@@ -38,10 +39,9 @@
38
39
  "cz-conventional-changelog": "3.3.0",
39
40
  "dirty-chai": "2.0.1",
40
41
  "mocha": "10.2.0",
41
- "moment": "2.29.4",
42
42
  "nyc": "15.1.0",
43
- "semantic-release": "20.1.0",
44
- "standard": "17.0.0"
43
+ "semantic-release": "21.0.3",
44
+ "standard": "17.1.0"
45
45
  },
46
46
  "scripts": {
47
47
  "lint": "standard",
package/plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schedule-plugin",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "label": "Tymly Schedule Plugin",
5
5
  "author": "WMFS",
6
6
  "organisation": "West Midlands Fire Service",
@@ -7,10 +7,10 @@ const ruleToDatetime = require('../lib/components/services/schedule/utils/rule-t
7
7
  const datetimeToRule = require('../lib/components/services/schedule/utils/datetime-to-rule')
8
8
 
9
9
  describe('Rule to datetime tests', function () {
10
- it('No options, should default to now', () => {
11
- const now = new Date()
12
- const datetime = ruleToDatetime()
10
+ it('No options, should default to now (UTC)', () => {
11
+ const now = moment().utc().toDate()
13
12
 
13
+ const datetime = ruleToDatetime()
14
14
  expect(datetime.getFullYear()).to.eql(now.getFullYear())
15
15
  expect(datetime.getMonth()).to.eql(now.getMonth())
16
16
  expect(datetime.getDate()).to.eql(now.getDate())
@@ -20,7 +20,8 @@ describe('Rule to datetime tests', function () {
20
20
  })
21
21
 
22
22
  it('Year only, the rest defaults to now', () => {
23
- const now = new Date()
23
+ let now = new Date()
24
+ now = moment(now).utc().toDate()
24
25
  const year = now.getFullYear() + 2
25
26
 
26
27
  const datetime = ruleToDatetime({ year })
@@ -34,49 +35,55 @@ describe('Rule to datetime tests', function () {
34
35
  })
35
36
 
36
37
  it('All options passed in as integers', () => {
38
+ const now = new Date()
37
39
  const rule = {
38
- year: 2020,
39
- month: 1,
40
- date: 2,
41
- hour: 12,
42
- minute: 30,
43
- second: 0
40
+ year: now.getFullYear(),
41
+ month: now.getMonth(),
42
+ date: now.getDate(),
43
+ hour: now.getHours(),
44
+ minute: now.getMinutes(),
45
+ second: now.getSeconds()
44
46
  }
45
47
 
46
48
  const datetime = ruleToDatetime(rule)
47
49
 
48
- expect(datetime.getFullYear()).to.eql(rule.year)
49
- expect(datetime.getMonth()).to.eql(rule.month)
50
- expect(datetime.getDate()).to.eql(rule.date)
51
- expect(datetime.getHours()).to.eql(rule.hour)
52
- expect(datetime.getMinutes()).to.eql(rule.minute)
53
- expect(datetime.getSeconds()).to.eql(rule.second)
50
+ const utcTimestamp = moment(now).utc().toDate()
51
+
52
+ expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
53
+ expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
54
+ expect(datetime.getDate()).to.eql(utcTimestamp.getDate())
55
+ expect(datetime.getHours()).to.eql(utcTimestamp.getHours())
56
+ expect(datetime.getMinutes()).to.eql(utcTimestamp.getMinutes())
57
+ expect(datetime.getSeconds()).to.eql(utcTimestamp.getSeconds())
54
58
  })
55
59
 
56
60
  it('All options passed in as strings', () => {
61
+ const now = new Date()
57
62
  const rule = {
58
- year: '2020',
59
- month: '1',
60
- date: '2',
61
- hour: '12',
62
- minute: '30',
63
- second: '0'
63
+ year: '' + now.getFullYear(),
64
+ month: '' + now.getMonth(),
65
+ date: '' + now.getDate(),
66
+ hour: '' + now.getHours(),
67
+ minute: '' + now.getMinutes(),
68
+ second: '' + now.getSeconds()
64
69
  }
65
70
 
66
71
  const datetime = ruleToDatetime(rule)
67
72
 
68
- expect(datetime.getFullYear().toString()).to.eql(rule.year)
69
- expect(datetime.getMonth().toString()).to.eql(rule.month)
70
- expect(datetime.getDate().toString()).to.eql(rule.date)
71
- expect(datetime.getHours().toString()).to.eql(rule.hour)
72
- expect(datetime.getMinutes().toString()).to.eql(rule.minute)
73
- expect(datetime.getSeconds().toString()).to.eql(rule.second)
73
+ const utcTimestamp = moment(now).utc().toDate()
74
+
75
+ expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
76
+ expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
77
+ expect(datetime.getDate()).to.eql(utcTimestamp.getDate())
78
+ expect(datetime.getHours()).to.eql(utcTimestamp.getHours())
79
+ expect(datetime.getMinutes()).to.eql(utcTimestamp.getMinutes())
80
+ expect(datetime.getSeconds()).to.eql(utcTimestamp.getSeconds())
74
81
  })
75
82
  })
76
83
 
77
84
  describe('Datetime to rule tests', function () {
78
- it('No options, should default to now', () => {
79
- const now = moment()
85
+ it('No options, should default to now (UTC)', () => {
86
+ const now = moment().utc()
80
87
  const rule = datetimeToRule()
81
88
 
82
89
  expect(rule.year).to.eql(now.year())
@@ -87,47 +94,35 @@ describe('Datetime to rule tests', function () {
87
94
  expect(rule.second).to.eql(now.second())
88
95
  })
89
96
 
90
- it('Specific year, the rest should default to now', () => {
91
- let datetime = new Date()
92
- const year = datetime.getFullYear() + 2
93
- datetime.setFullYear(year)
94
-
95
- const rule = datetimeToRule(datetime)
96
- datetime = moment(datetime)
97
-
98
- expect(rule.year).to.eql(year)
99
- expect(rule.month).to.eql(datetime.month())
100
- expect(rule.date).to.eql(datetime.date())
101
- expect(rule.hour).to.eql(datetime.hour())
102
- expect(rule.minute).to.eql(datetime.minute())
103
- expect(rule.second).to.eql(datetime.second())
104
- })
105
-
106
97
  it('DST test, should change time by +1 hour', () => {
107
- const currentDateTime = new Date('Sunday March 27 2022 00:59:00')
98
+ const lastMinuteOfGMT = new Date('Sunday March 27 2022 00:59:00')
99
+ console.log(`last minute of GMT: ${lastMinuteOfGMT}`)
108
100
 
109
- // 2022-03-27T02:00:00+01:00
110
- const startDSTDateTime = moment(currentDateTime).add(1, 'minutes')
101
+ let startOfBSTDateTime = moment(lastMinuteOfGMT).add(1, 'minutes').toDate()
102
+ console.log(`start of BST: ${startOfBSTDateTime}`)
111
103
 
112
104
  // adding 1 min and setting as Date object
113
- const rule = datetimeToRule(new Date(currentDateTime.getTime() + (60 * 1000)))
105
+ const rule = datetimeToRule(new Date(lastMinuteOfGMT.getTime() + (60 * 1000)))
114
106
 
115
- expect(rule.date).to.eql(startDSTDateTime.date())
116
- expect(rule.hour).to.eql(startDSTDateTime.hour())
117
- expect(rule.minute).to.eql(startDSTDateTime.minute())
107
+ startOfBSTDateTime = moment(startOfBSTDateTime).utc()
108
+ expect(rule.date).to.eql(startOfBSTDateTime.date())
109
+ expect(rule.hour).to.eql(startOfBSTDateTime.hour())
110
+ expect(rule.minute).to.eql(startOfBSTDateTime.minute())
118
111
  })
119
112
 
120
113
  it('DST test, should change time by -1 hour', () => {
121
- const currentDateTime = new Date('Sunday October 30 2022 01:59:00')
114
+ const lastMinuteOfBST = new Date('Sunday October 30 2022 01:59:00')
115
+ console.log(`last minute of BST: ${lastMinuteOfBST}`)
122
116
 
123
- // 2022-10-30T01:00:00+00:00
124
- const endDSTDateTime = moment(currentDateTime).add(1, 'minutes')
117
+ let startOfGMTDateTime = moment(lastMinuteOfBST).add(1, 'minutes').toDate()
118
+ console.log(`start of GMT: ${startOfGMTDateTime}`)
125
119
 
126
120
  // adding 1 min and setting as Date object
127
- const rule = datetimeToRule(new Date(currentDateTime.getTime() + (60 * 1000)))
121
+ const rule = datetimeToRule(new Date(lastMinuteOfBST.getTime() + (60 * 1000)))
128
122
 
129
- expect(rule.date).to.eql(endDSTDateTime.date())
130
- expect(rule.hour).to.eql(endDSTDateTime.hour())
131
- expect(rule.minute).to.eql(endDSTDateTime.minute())
123
+ startOfGMTDateTime = moment(startOfGMTDateTime).utc()
124
+ expect(rule.date).to.eql(startOfGMTDateTime.date())
125
+ expect(rule.hour).to.eql(startOfGMTDateTime.hour())
126
+ expect(rule.minute).to.eql(startOfGMTDateTime.minute())
132
127
  })
133
128
  })
@@ -3,6 +3,7 @@
3
3
  const expect = require('chai').expect
4
4
  const tymly = require('@wmfs/tymly')
5
5
  const path = require('path')
6
+ const moment = require('moment')
6
7
 
7
8
  const scheduleKey = 'tymlyTest_twoSecondCatUpdates'
8
9
 
@@ -100,8 +101,8 @@ describe('Tymly schedule tests', function () {
100
101
  })
101
102
 
102
103
  it('update task to specific date/time', async () => {
103
- const datetime = new Date()
104
- datetime.setSeconds(datetime.getSeconds() + 10)
104
+ const datetime = moment().utc().add(10, 'seconds').toDate()
105
+ console.log(`scheduled: ${datetime}`)
105
106
 
106
107
  await scheduleService.stopAndUpdateTaskSchedule(
107
108
  scheduleKey,