-
Couldn't load subscription status.
- Fork 0
Open
Description
There are a number of methods in the API that take no arguments, do no modifications, and return only scalar values.
For example, retrieving the components of a zoned or datetime:
Lines 617 to 633 in fd8112c
| year() { | |
| return DllCall("tempus_ahk\zoned_year", "Ptr", this.pointer, "Short") | |
| } | |
| month() { | |
| return DllCall("tempus_ahk\zoned_month", "Ptr", this.pointer, "Char") | |
| } | |
| day() { | |
| return DllCall("tempus_ahk\zoned_day", "Ptr", this.pointer, "Char") | |
| } | |
| hour() { | |
| return DllCall("tempus_ahk\zoned_hour", "Ptr", this.pointer, "Char") | |
| } | |
| minute() { | |
| return DllCall("tempus_ahk\zoned_minute", "Ptr", this.pointer, "Char") | |
| } | |
| second() { | |
| return DllCall("tempus_ahk\zoned_second", "Ptr", this.pointer, "Char") |
It might be more natural for these to be accessed as simple properties. For example, instead of:
#Include "tempus.ahk"
dt := DateTime.parse("2025-02-27T01:02:03")
; normally we would use `strftime`, but for sake of example...
result := Format("{}/{}/{}", dt.year(), dt.month(), dt.day())
MsgBox(result)These are essentially getters that could just use properties instead:
#Include "tempus.ahk"
dt := DateTime.parse("2025-02-27T01:02:03")
; normally we would use `strftime`, but for sake of example...
result := Format("{}/{}/{}", dt.year, dt.month, dt.day)
MsgBox(result)This feels a bit more natural.
AutoHotkey provides class objects with the ability to define properties in the following forms:
class ClassName {
Property[Parameters] ; Use brackets only when parameters are present.
{
get {
return value of property
}
set {
Store or otherwise handle value
}
}
ShortProperty
{
get => Expression which calculates property value
set => Expression which stores or otherwise handles value
}
ShorterProperty => Expression which calculates property value
}So getters like year() could perhaps better rewritten as properties. Maybe something like:
year => DllCall("tempus_ahk\zoned_year", "Ptr", this.pointer, "Short")Metadata
Metadata
Assignees
Labels
No labels