@wmfs/tymly-schedule-plugin 1.6.0 → 1.7.0

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.
package/.releaserc.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "@semantic-release/git"
13
13
  ],
14
14
  "generateNotes": {
15
- "preset": "metahub"
15
+ "preset": "angular"
16
16
  },
17
17
  "prepare": [
18
18
  {
package/.version CHANGED
@@ -1 +1 @@
1
- VERSION=1.6.0
1
+ VERSION=1.7.0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ # [1.7.0](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.6.1...v1.7.0) (2024-07-02)
2
+
3
+ ## [1.6.1](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.6.0...v1.6.1) (2023-06-07)
4
+
5
+
6
+ ### 🐛 Bug Fixes
7
+
8
+ * better utc handling with consequent test updates ([d15c042](https://github.com/wmfs/tymly-schedule-plugin/commit/d15c042987ebb61fb382eedb057413d718e825ea))
9
+
10
+
11
+ ### 🛠 Builds
12
+
13
+ * **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))
14
+ * **deps-dev:** update dependency semantic-release to v21.0.3 ([b2da7ba](https://github.com/wmfs/tymly-schedule-plugin/commit/b2da7babde8a45e0d899870ee5b4021c8a662d3b))
15
+ * **deps-dev:** update dependency standard to v17.1.0 ([f7def04](https://github.com/wmfs/tymly-schedule-plugin/commit/f7def04f6abdb127fb0aa6ad02cc7b069480dee9))
16
+
17
+
18
+ ### 📦 Code Refactoring
19
+
20
+ * renamed vars to improve clarity ([4ed331c](https://github.com/wmfs/tymly-schedule-plugin/commit/4ed331c0edbbd3740e72b18961122d2710ce4e39))
21
+
22
+
23
+ ### 🚨 Tests
24
+
25
+ * minor change from let to const for standard ([e81e5de](https://github.com/wmfs/tymly-schedule-plugin/commit/e81e5dec130e9d35ad9460a316a3bce42ea9fcfc))
26
+ * restored tests that were inadvertantly removed ([843e6d5](https://github.com/wmfs/tymly-schedule-plugin/commit/843e6d5e0ddd9e5046e39df8ff068e489e7fdfd7))
27
+
1
28
  # [1.6.0](https://github.com/wmfs/tymly-schedule-plugin/compare/v1.5.0...v1.6.0) (2023-06-06)
2
29
 
3
30
 
@@ -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(),
@@ -12,7 +12,6 @@ module.exports = function (rule = {}) {
12
12
  )
13
13
  // note that rule does not specify a timezone, so we have to assume that
14
14
  // the timestamp provided is a local timestamp - as such, we have to convert
15
- // to UTC. note that in British Summer Time (for example, on the 5th June),
16
- // now.getTimezoneOffset() will return -60.
17
- return moment(date).add(now.getTimezoneOffset(), 'minutes').toDate()
15
+ // to UTC
16
+ return moment(date).utc().toDate()
18
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wmfs/tymly-schedule-plugin",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
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,25 +23,25 @@
23
23
  "main": "./lib/index.js",
24
24
  "dependencies": {
25
25
  "node-schedule": "2.1.1",
26
- "uuid": "^9.0.0",
27
- "moment": "2.29.4"
26
+ "uuid": "^10.0.0",
27
+ "moment": "2.30.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@semantic-release/changelog": "6.0.3",
31
31
  "@semantic-release/exec": "6.0.3",
32
32
  "@semantic-release/git": "10.0.1",
33
33
  "@wmfs/tymly": "1.242.0",
34
- "@wmfs/tymly-pg-plugin": "1.282.0",
35
- "@wmfs/tymly-test-helpers": "1.22.2",
36
- "chai": "4.3.7",
34
+ "@wmfs/tymly-pg-plugin": "1.292.0",
35
+ "@wmfs/tymly-test-helpers": "1.23.0",
36
+ "chai": "4.4.1",
37
37
  "codecov": "3.8.3",
38
38
  "conventional-changelog-metahub": "4.0.1",
39
39
  "cz-conventional-changelog": "3.3.0",
40
40
  "dirty-chai": "2.0.1",
41
- "mocha": "10.2.0",
42
- "nyc": "15.1.0",
43
- "semantic-release": "21.0.0",
44
- "standard": "17.0.0"
41
+ "mocha": "10.5.2",
42
+ "nyc": "17.0.0",
43
+ "semantic-release": "24.0.0",
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.6.0",
3
+ "version": "1.7.0",
4
4
  "label": "Tymly Schedule Plugin",
5
5
  "author": "WMFS",
6
6
  "organisation": "West Midlands Fire Service",
@@ -8,10 +8,9 @@ const datetimeToRule = require('../lib/components/services/schedule/utils/dateti
8
8
 
9
9
  describe('Rule to datetime tests', function () {
10
10
  it('No options, should default to now (UTC)', () => {
11
- let now = new Date()
12
- now = moment(now).add(now.getTimezoneOffset(), 'minutes').toDate()
13
- const datetime = ruleToDatetime()
11
+ const now = moment().utc().toDate()
14
12
 
13
+ const datetime = ruleToDatetime()
15
14
  expect(datetime.getFullYear()).to.eql(now.getFullYear())
16
15
  expect(datetime.getMonth()).to.eql(now.getMonth())
17
16
  expect(datetime.getDate()).to.eql(now.getDate())
@@ -22,7 +21,7 @@ describe('Rule to datetime tests', function () {
22
21
 
23
22
  it('Year only, the rest defaults to now', () => {
24
23
  let now = new Date()
25
- now = moment(now).add(now.getTimezoneOffset(), 'minutes').toDate()
24
+ now = moment(now).utc().toDate()
26
25
  const year = now.getFullYear() + 2
27
26
 
28
27
  const datetime = ruleToDatetime({ year })
@@ -48,7 +47,7 @@ describe('Rule to datetime tests', function () {
48
47
 
49
48
  const datetime = ruleToDatetime(rule)
50
49
 
51
- const utcTimestamp = moment(now).add(now.getTimezoneOffset(), 'minutes').toDate()
50
+ const utcTimestamp = moment(now).utc().toDate()
52
51
 
53
52
  expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
54
53
  expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
@@ -71,7 +70,7 @@ describe('Rule to datetime tests', function () {
71
70
 
72
71
  const datetime = ruleToDatetime(rule)
73
72
 
74
- const utcTimestamp = moment(now).add(now.getTimezoneOffset(), 'minutes').toDate()
73
+ const utcTimestamp = moment(now).utc().toDate()
75
74
 
76
75
  expect(datetime.getFullYear()).to.eql(utcTimestamp.getFullYear())
77
76
  expect(datetime.getMonth()).to.eql(utcTimestamp.getMonth())
@@ -83,8 +82,8 @@ describe('Rule to datetime tests', function () {
83
82
  })
84
83
 
85
84
  describe('Datetime to rule tests', function () {
86
- it('No options, should default to now', () => {
87
- const now = moment()
85
+ it('No options, should default to now (UTC)', () => {
86
+ const now = moment().utc()
88
87
  const rule = datetimeToRule()
89
88
 
90
89
  expect(rule.year).to.eql(now.year())
@@ -95,47 +94,35 @@ describe('Datetime to rule tests', function () {
95
94
  expect(rule.second).to.eql(now.second())
96
95
  })
97
96
 
98
- it('Specific year, the rest should default to now', () => {
99
- let datetime = new Date()
100
- const year = datetime.getFullYear() + 2
101
- datetime.setFullYear(year)
102
-
103
- const rule = datetimeToRule(datetime)
104
- datetime = moment(datetime)
105
-
106
- expect(rule.year).to.eql(year)
107
- expect(rule.month).to.eql(datetime.month())
108
- expect(rule.date).to.eql(datetime.date())
109
- expect(rule.hour).to.eql(datetime.hour())
110
- expect(rule.minute).to.eql(datetime.minute())
111
- expect(rule.second).to.eql(datetime.second())
112
- })
113
-
114
97
  it('DST test, should change time by +1 hour', () => {
115
- 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}`)
116
100
 
117
- // 2022-03-27T02:00:00+01:00
118
- const startDSTDateTime = moment(currentDateTime).add(1, 'minutes')
101
+ let startOfBSTDateTime = moment(lastMinuteOfGMT).add(1, 'minutes').toDate()
102
+ console.log(`start of BST: ${startOfBSTDateTime}`)
119
103
 
120
104
  // adding 1 min and setting as Date object
121
- const rule = datetimeToRule(new Date(currentDateTime.getTime() + (60 * 1000)))
105
+ const rule = datetimeToRule(new Date(lastMinuteOfGMT.getTime() + (60 * 1000)))
122
106
 
123
- expect(rule.date).to.eql(startDSTDateTime.date())
124
- expect(rule.hour).to.eql(startDSTDateTime.hour())
125
- 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())
126
111
  })
127
112
 
128
113
  it('DST test, should change time by -1 hour', () => {
129
- 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}`)
130
116
 
131
- // 2022-10-30T01:00:00+00:00
132
- const endDSTDateTime = moment(currentDateTime).add(1, 'minutes')
117
+ let startOfGMTDateTime = moment(lastMinuteOfBST).add(1, 'minutes').toDate()
118
+ console.log(`start of GMT: ${startOfGMTDateTime}`)
133
119
 
134
120
  // adding 1 min and setting as Date object
135
- const rule = datetimeToRule(new Date(currentDateTime.getTime() + (60 * 1000)))
121
+ const rule = datetimeToRule(new Date(lastMinuteOfBST.getTime() + (60 * 1000)))
136
122
 
137
- expect(rule.date).to.eql(endDSTDateTime.date())
138
- expect(rule.hour).to.eql(endDSTDateTime.hour())
139
- 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())
140
127
  })
141
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,