Difference between revisions of "ObjectType:time"
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{ObjectType-Vitals|time|[[LavishScript]]|none|Same as '''Time24'''|time|no|struct tm *}} | ||
+ | |||
== Description == | == Description == | ||
The '''time''' type describes a date and time of day. Many other details are available, such as the month, day of week, and so on. This type also provides basic time calculation functionality | The '''time''' type describes a date and time of day. Many other details are available, such as the month, day of week, and so on. This type also provides basic time calculation functionality | ||
== Members == | == Members == | ||
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''Hour''': Hour of the day (0-23) |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''Minute''': Minute of the hour (0-59) |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''Second''': Second of the minute (0-59) |
− | *[[ | + | *[[ObjectType:int|int]] '''DayOfWeek''': Day of the week (1-7) |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''DayOfWeekPtr''': Day of the week (0-6) - Mainly useful for *setting* |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''Day''': Day of the month (1-31 depending on the month) |
− | *[[ | + | *[[ObjectType:int|int]] '''Month''': Month of the year (1-12) |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''MonthPtr''': Month of the year (0-11) - Mainly useful for *setting* |
− | *[[ | + | *[[ObjectType:int|int]] '''Year''': Year |
− | *[[ | + | *[[ObjectType:intptr|intptr]] '''YearPtr''': Year-1900 (e.g. 0 is 1900, 100 is 2000) - Mainly useful for *setting* |
− | *[[ | + | *[[ObjectType:string|string]] '''Time12''': Time in hh:mm:ss given in 12-hour format |
− | *[[ | + | *[[ObjectType:string|string]] '''Time24''': Time in hh:mm:ss given in 24-hour format |
− | *[[ | + | *[[ObjectType:string|string]] '''Date''': Date in mm/dd/yyyy |
− | *[[ | + | *[[ObjectType:bool|bool]] '''Night''': TRUE if current time is after 7pm and before 7am |
− | *[[ | + | *[[ObjectType:int|int]] '''SecondsSinceMidnight''': Number of seconds since midnight |
− | *[[ | + | *[[ObjectType:uint|uint]] '''Timestamp''': Number of seconds since epoch (standard UNIX timestamp) |
== Methods == | == Methods == | ||
*'''Set['''timestamp''']''': Sets the value based on the given timestamp (standard UNIX timestamp, number of seconds since epoch) | *'''Set['''timestamp''']''': Sets the value based on the given timestamp (standard UNIX timestamp, number of seconds since epoch) | ||
*'''Update''': Updates the type after setting an individual member (NOT needed when using the Set method) | *'''Update''': Updates the type after setting an individual member (NOT needed when using the Set method) | ||
− | |||
− | |||
− | |||
== Declaring time Variables == | == Declaring time Variables == | ||
Line 32: | Line 31: | ||
This sets a variable to the current time, which can be manipulated later. | This sets a variable to the current time, which can be manipulated later. | ||
Declare TimeVar time ${Time.Timestamp} | Declare TimeVar time ${Time.Timestamp} | ||
+ | |||
+ | == Setting date Values == | ||
+ | |||
+ | declare myDate time local | ||
+ | myDate.Day:Set[31] | ||
+ | myDate.MonthPtr:Set[11] /*month -1 */ | ||
+ | myDate.YearPtr:Set[99] /*year -1900 */ | ||
+ | myDate:Update | ||
+ | echo ${myDate.Date} | ||
+ | |||
+ | ;Output 12/31/1999 | ||
== Setting time Values == | == Setting time Values == | ||
Line 50: | Line 60: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Comparing time Values == | == Comparing time Values == | ||
Line 66: | Line 67: | ||
echo TimeVar is ${Math.Calc[${TimeVar.Timestamp}-${Time.Timestamp}]} seconds into the future! | echo TimeVar is ${Math.Calc[${TimeVar.Timestamp}-${Time.Timestamp}]} seconds into the future! | ||
− | |||
− | |||
== See Also == | == See Also == | ||
− | + | {{LavishScript:ObjectType}} | |
− | |||
− | |||
− |
Latest revision as of 16:23, 8 July 2018
time | |
Defined By | LavishScript |
Inherits | none |
Reduces To | Same as Time24 |
Variable Object Type | time |
Uses Sub-Types | no |
C/C++ Type | struct tm * |
Contents
Description
The time type describes a date and time of day. Many other details are available, such as the month, day of week, and so on. This type also provides basic time calculation functionality
Members
- intptr Hour: Hour of the day (0-23)
- intptr Minute: Minute of the hour (0-59)
- intptr Second: Second of the minute (0-59)
- int DayOfWeek: Day of the week (1-7)
- intptr DayOfWeekPtr: Day of the week (0-6) - Mainly useful for *setting*
- intptr Day: Day of the month (1-31 depending on the month)
- int Month: Month of the year (1-12)
- intptr MonthPtr: Month of the year (0-11) - Mainly useful for *setting*
- int Year: Year
- intptr YearPtr: Year-1900 (e.g. 0 is 1900, 100 is 2000) - Mainly useful for *setting*
- string Time12: Time in hh:mm:ss given in 12-hour format
- string Time24: Time in hh:mm:ss given in 24-hour format
- string Date: Date in mm/dd/yyyy
- bool Night: TRUE if current time is after 7pm and before 7am
- int SecondsSinceMidnight: Number of seconds since midnight
- uint Timestamp: Number of seconds since epoch (standard UNIX timestamp)
Methods
- Set[timestamp]: Sets the value based on the given timestamp (standard UNIX timestamp, number of seconds since epoch)
- Update: Updates the type after setting an individual member (NOT needed when using the Set method)
Declaring time Variables
time variables are initialized with a Timestamp. If a "default" is not given, it will default to the equivalent of timestamp 0.
Example 1
This sets a variable to the current time, which can be manipulated later.
Declare TimeVar time ${Time.Timestamp}
Setting date Values
declare myDate time local myDate.Day:Set[31] myDate.MonthPtr:Set[11] /*month -1 */ myDate.YearPtr:Set[99] /*year -1900 */ myDate:Update echo ${myDate.Date}
- Output 12/31/1999
Setting time Values
time variables can be set as a whole by using the Set method, or some individual portions may be set via the intptr type's members. After setting individual portions, you should use time:Update in order to completely update the structure. This will make sure the date and time are actually valid -- for example, setting the "Day" to -1 and updating will result in the last day of the previous month.
Declare TimeVar time ${Time.Timestamp} ; Decrease the "day" by 14. This may result in a negative value of Day, but ; when TimeVar:Update is used, it will be the correct date for "2 weeks ago" TimeVar.Day:Dec[14] ; This may show something like 05/-13/2005 echo ${TimeVar.Date} ; Update TimeVar TimeVar:Update ; This will be a real date echo ${TimeVar.Date} ; This will set the timestamp to the current time and date again TimeVar:Set[${Time.Timestamp}] echo ${TimeVar.Date} ${TimeVar.Time}
Comparing time Values
Time comparison is actually quite simple. Rather than doing string comparisons, simply use the Timestamp member:
if "${TimeVar.Timestamp}>${Time.Timestamp}" echo TimeVar is ${Math.Calc[${TimeVar.Timestamp}-${Time.Timestamp}]} seconds into the future!
See Also
LavishScript Object Types
- Text
- string - mutablestring - unistring
- Numbers
- byte - float - float64 - int - uint - int64
- Boolean (TRUE/FALSE)
- bool
- Pointers
- boolptr - byteptr - floatptr - float64ptr - intptr - uintptr - int64ptr - rgbptr - stringptr
- Containers
- objectcontainer - array - index - collection - queue - stack - set - variablescope
- JSON
- jsonobject - jsonarray - jsonvaluecontainer - jsonvalue
- Iteration
- iterator - jsoniterator
- Date/Time
- time
- File Handling
- filepath - file - filelist - filelistentry
- Tasks
- lavishmachine - Accessed via the Top-Level Object LMAC
- task - tasklibrary - taskmanager - tasktype - taskpulseargs - elmactaskstate