Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/blocks/utility/current_time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @type {import('#types').BlockDefinitionRaw} */
export default {
type: 'io_utility_current_time',
name: "Current Time",
color: 360,
description: "Get the current system time in 24-hour format for use in time comparisons and conditions. Returns the current hour and minute as a time value that can be compared with Time blocks. Perfect for creating time-based automation logic like 'if current time > 14:30' or 'if current time is between 9:00 and 17:00'. Found in the Time category alongside Time block.",
connections: {
mode: "value",
output: ["expression", "time"],
},
template: "Current Time",
generators: {
json: () => {
return [JSON.stringify({
currentTime: {}
}), 0]
}
},
regenerators: {
json: (blockObject, helpers) => {
if (!blockObject.currentTime) {
throw new Error("No currentTime data for io_utility_current_time regenerator")
}

return {
type: 'io_utility_current_time'
}
}
}
}
67 changes: 67 additions & 0 deletions app/blocks/utility/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { makeOptions } from "#app/util/fields.js"

/** @type {import('#types').BlockDefinitionRaw} */
export default {
type: 'io_utility_time',
name: "Time",
color: 360,
description: "Create a time value in 24-hour format for use in comparisons and conditions. Perfect for building time-based logic like 'if current time > 14:30' or 'if time equals 09:00'. Hours range from 00-23, minutes from 00-59. The time value can be compared with other times or used in mathematical operations. Found in the Time category alongside Current Time block.",
connections: {
mode: "value",
output: ["expression", "time"],
},
template: "%HOUR : %MINUTE",
fields: {
HOUR: {
description: "Select the hour in 24-hour format (00-23). Examples: 00 for midnight, 12 for noon, 14 for 2 PM, 23 for 11 PM. This military time format ensures precise time comparisons without AM/PM confusion.",
options: makeOptions({
upTo: 24,
valueFunc: hour => hour.toString().padStart(2, '0')
})
},
MINUTE: {
description: "Select the minute (00-59). Examples: 00 for on the hour, 15 for quarter past, 30 for half past, 45 for quarter to. Combined with hours, creates precise time values for your automation logic.",
options: makeOptions({
upTo: 60,
valueFunc: minute => minute.toString().padStart(2, '0')
})
}
},
generators: {
json: block => {
const
hour = block.getFieldValue('HOUR'),
minute = block.getFieldValue('MINUTE'),
timeValue = `${hour}:${minute}`,
// Convert to minutes since midnight for numeric comparison
totalMinutes = parseInt(hour, 10) * 60 + parseInt(minute, 10)

return [JSON.stringify({
time: {
display: timeValue,
value: totalMinutes
}
}), 0]
}
},
regenerators: {
json: (blockObject, helpers) => {
const timeData = blockObject.time
if (!timeData) {
throw new Error("No time data for io_utility_time regenerator")
}

const totalMinutes = timeData.value
const hour = Math.floor(totalMinutes / 60).toString().padStart(2, '0')
const minute = (totalMinutes % 60).toString().padStart(2, '0')

return {
type: 'io_utility_time',
fields: {
HOUR: hour,
MINUTE: minute
}
}
}
}
}
2 changes: 2 additions & 0 deletions app/toolbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Math from './math.js'
import Notifications from './notifications.js'
import Weather from './weather.js'
import Text from './text.js'
import Time from './time.js'
import Triggers from './triggers.js'
import Utility from './utility.js'
import Variables from './variables.js'
Expand All @@ -15,6 +16,7 @@ export default [
Logic,
Math,
Text,
Time,
Variables,
Feeds,
Notifications,
Expand Down
8 changes: 8 additions & 0 deletions app/toolbox/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
name: 'Time',
colour: 360,
contents: [
'io_utility_time',
'io_utility_current_time'
]
}
Loading