Skip to content

Commit

Permalink
- Bugfix: Set Last date on **Hit count** as localized date
Browse files Browse the repository at this point in the history
  • Loading branch information
runely committed Oct 24, 2023
1 parent 803936e commit 29e2610
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ Visit [this tutorial](https://community.athom.com/t/trigger-a-flow-using-calenda

## Changelog

- 2.3.3
- Bugfix: Set `Last` date on **Hit count** as localized date
- 2.3.2
- Bugfix: Triggers with arguments would trigger number of times that triggercard has been added to a flow 😬 ...
- throw - Updated text
Expand Down
17 changes: 13 additions & 4 deletions lib/hit-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
const { flow: { triggers } } = require('../app.json')
const { moment } = require('./moment-datetime')

const generateLastTriggered = (app) => {
let now = moment({ timezone: app.getTimezone() })
now.locale(app.homey.__('locale.moment'))
const lastTriggered = now.format(`${app.variableMgmt.dateTimeFormat.long} ${app.variableMgmt.dateTimeFormat.time}`)

now = null
return lastTriggered
}

const getHitCountData = (app) => {
const temp = app.homey.settings.get(app.variableMgmt.hitCount.data)
return !temp ? undefined : JSON.parse(temp)
Expand Down Expand Up @@ -84,13 +93,13 @@ const updateHitCount = (app, id, args = undefined) => {
if (args === undefined) {
if (trigger.variants.length === 0) {
trigger.variants.push({
lastTriggered: moment({ timezone: app.getTimezone() }).format(`${app.variableMgmt.dateTimeFormat.long} ${app.variableMgmt.dateTimeFormat.time}`),
lastTriggered: generateLastTriggered(app),
today: 1,
total: 1
})
app.log(`updateHitCount : Trigger variant added for ${id} :`, trigger.variants[0])
} else {
trigger.variants[0].lastTriggered = moment({ timezone: app.getTimezone() }).format(`${app.variableMgmt.dateTimeFormat.long} ${app.variableMgmt.dateTimeFormat.time}`)
trigger.variants[0].lastTriggered = generateLastTriggered(app)
trigger.variants[0].today++
trigger.variants[0].total++
app.log(`updateHitCount : Trigger variant for ${id} updated`, trigger.variants[0])
Expand All @@ -114,13 +123,13 @@ const updateHitCount = (app, id, args = undefined) => {
if (!variant) {
trigger.variants.push({
...args,
lastTriggered: moment({ timezone: app.getTimezone() }).format(`${app.variableMgmt.dateTimeFormat.long} ${app.variableMgmt.dateTimeFormat.time}`),
lastTriggered: generateLastTriggered(app),
today: 1,
total: 1
})
app.log(`updateHitCount : Trigger variant added for ${id} :`, trigger.variants[trigger.variants.length - 1])
} else {
variant.lastTriggered = moment({ timezone: app.getTimezone() }).format(`${app.variableMgmt.dateTimeFormat.long} ${app.variableMgmt.dateTimeFormat.time}`)
variant.lastTriggered = generateLastTriggered(app)
variant.today++
variant.total++
app.log(`updateHitCount : Trigger variant for ${id} updated`, variant)
Expand Down
1 change: 1 addition & 0 deletions tests/hit-count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let runtimeData = JSON.parse(dataAsText)
const app = {
getTimezone: () => 'Europe/Oslo',
homey: {
__: jest.fn(),
i18n: {
getLanguage: () => 'no'
},
Expand Down

0 comments on commit 29e2610

Please sign in to comment.