hec.hectime
Module to provide native python compatibility for the hec.heclib.util.HecTime java class
NOTE Static java fields and methods are now module constants and functions (e.g., java HecTime.isLeap() -> python hectime.is_leap())
Jump to class HecTime
The value for a time integer that repsents that the time has either not been set yet or has been set incorrectly.
Value that specifies that each granule represents one second
- Values are offset from
[1970, 1, 1, 0, 0, 0] - Earliest represntable time is
[1901, 12, 13, 20, 45, 52](integer value =-2147483648) - Latest represntable time is
[2038, 1, 19, 3, 14, 7](integer value =2147483647)
Value that specifies that each granule represents one minute. New HecTime objects default to this granularity if not otherwise specified.
- Values are offset from
[1899, 12, 31, 0, 0, 0] - Earliest represntable time is
[-2184, 12, 6, 21, 52, 0](integer value =-2147483648) - Latest represntable time is
[5983, 1, 23, 2, 7, 0](integer value =2147483647)
Value that specifies that each granule represents one hour
- Values are offset from
[1899, 12, 31, 0, 0, 0] - Earliest represntable time is
[-243084, 3, 22, 16, 0, 0](integer value =-2147483648) - Latest represntable time is
[246883, 10, 8, 7, 0, 0](integer value =2147483647)
Value that specifies that each granule represents one day
- Values are offset from
[1899, 12, 31, 0, 0, 0] - Earliest represntable time is
[-5877711, 6, 22, 0, 0, 0](integer value =-2147483645) - Latest represntable time is
[5879610, 7, 10, 0, 0, 0](integer value =2147483647)
Converts 2-digit years into 4 digit years.
If the year passed in is not in the range 0..99, the year is returned unchanged
Arguments:
- y (int): The year
Returns:
int: The year as a 4 digit year
Normalizes in integer list of either [julian, minute] or [year, month, day, hour, minute, second]
Arguments:
- values (list[int]): Either
[julian, minute]or `[year, month, day, hour, minute, second]
Returns the complete number of intervals between two times
Arguments:
- start_time (int): The time to compute the number of intervals from, in julian * 1440 + minutes_since_midnight
- end_time (int): The time to compute the number of intervals to, in julian * 1440 + minutes_since_midnight
- interval (Union[Interval, int]): The interval to compute the number for. If an integer, it must the the
- actual or characteristic minutes value of a standard Interval object.
Raises:
- HecTimeException: if the interval is not one of the standard intervals
Returns:
int: The number of complete intervals between the two times
Converts an HecTime object from one time zone to another, optionally specifyintg that the target time zone does not observe Daylight Saving Time (DST). Only for HecTime objects convertable to datetime objects (between 01Jan0001, 00:00 and 31Dec9999, 23:59).
Arguments:
- hectime (HecTime): The HecTime object to convert
- from_time_zone (ZoneInfo): The time zone that the object is currently in
- to_time_zone (ZoneInfo): The target time
- respect_daylight_savings (Optional[bool]): Specifies whether the target time zone.
should observe DST. Defaults to True.
- If
True, the target time zone is used as specified - If
Falseand the specified target time zone observes DST, then a time zone is found that has the same UTC offset as the specified target time zone but does not observe DST.
- If
Raises:
- HecTimeException: - If the HecTime object has an attached time zone that is not the same as
from_time_zone.- If
respect_daylight_savingsisTrue,to_time_zoneobserves DST and no equivalent time zone could be found that does not observer DST - If the HecTime object is not convertable to a datetime object
- If
Get the current timm as days since 1899 and minutes past midnight and return in parameters.
Arguments:
- julian (list[int]): A list of length > 0 whose first value receives the current days since 1899
- minutes (list[int]): A list of length > 0 whose first value receives the current minutes past midnight
Deprecated:
Normalizes a time specified in days since 1899 and minutes past midnight so that 0 <= minutes_out < 1440
Arguments:
- julian_in (int): _description_
- minutes_in (int): _description_
- julian_out (list[int]): _description_
- minutes_out (list[int]): _description_
Parses a date string and sets the the number of days since 1899 in the return variable
Arguments:
- datestr (str): The date string (may contain time portion)
- julian (list[int]): A list of length > 0 that whose first element receives the days since 1988
Raises:
- HecTimeException: if the date string cannot be successfully parsed
Parses a date string and sets the year, month, and day in the return variable
Arguments:
- datestr (str): The date string to parse (may contain a time portion)
- ymd (list[int]): A list of length > 2 whose first three elements receive the year, month, and day
Returns:
int: 0 on success or -1 otherwise
Return a time integer for specified time values and granularity
Arguments:
- values (list[int]): The time values (
[year, month, day, hour, minute, second]) - granularity (int): The granularity of the time integer to return
Raises:
- HecTimeException: if values is less than six items in length
- HecTimeException: if the specified granularity is not valid
Returns:
int: The time integer for the specified time values and granularity
See:
Return time values for a time value and granularity
NOTE This function always returns midnight as [..., 0, 0, 0].
Use to2400(...) to get midnight as hour 24
Arguments:
- time_int (int): The time integer to return the time values for
- granularity (int): The granularity of the time integer
Raises:
- HecTimeException: if time_int is not valid for the specified granularity
Returns:
list[int]: The list of time values (
[year, month, day, hour, minute, second]) represented by the time integer in and granularity
Parses or computes the start and end of a time window specified as a string in the general form
start_time end_time and return the computed times in the specified parameters.
Arguments:
- time_window_str (str): The time window string. Both start time and end time may be absolute times or relative times.
The string is not case sensitive, but the start and end times must be separated by a comma or whitespace.
- If absolute:
- may contain commas and/or spaces
- may specify a time portion or not:
- If relative:
- may not contain commas or spaces
- are of the format <anchor><offset>... where each offset is of the format [+-]<count><unit>
Multiple offsets are allowed.
- Valid anchors are:
Tthe current timeDthe start of the current dayBorS- the start time (allowed only on end time and end must not depend on start time)E- the end time (allowed only on start time and the start time must not depend on end time)
- The unit for each offset must be one of:
Y- year(s)M- month(s)D- days(s)H- hour(s)
- Valid anchors are:
- Examples:
01Aug2024, 01:00 31Aug2024 24002024-01-01 2024-12-31,24:00t-7d, te-1m+1d-2h,d01Aug2024, 01:00, s+1m
- If absolute:
- start_time (HecTime): Is set to the parsed or computed start time if returned status == 0
- end_time (HecTime): Is set to the parsed or computed end time if returned status == 0
Returns:
int:
0on success or-1on failure to parse the string
Parses or computes the start and end of a time window specified as a string in the general form
start_time end_time and return the computed times in the specified parameters.
Arguments:
- time_window_str (str): The time window string. Both start time and end time may be absolute times or relative times.
The string is not case sensitive, but the start and end times must be separated by a comma or whitespace.
- If absolute:
- may contain commas and/or spaces
- may specify a time portion or not:
- If relative:
- may not contain commas or spaces
- are of the format <anchor><offset>... where each offset is of the format [+-]<count><unit>
Multiple offsets are allowed.
- Valid anchors are:
Tthe current timeDthe start of the current dayBorS- the start time (allowed only on end time and end must not depend on start time)E- the end time (allowed only on start time and the start time must not depend on end time)
- The unit for each offset must be one of:
Y- year(s)M- month(s)D- days(s)H- hour(s)
- Valid anchors are:
- Examples:
01Aug2024, 01:00 31Aug2024 24002024-01-01 2024-12-31,24:00t-7d, te-1m+1d-2h,d01Aug2024, 01:00, s+1m
- If absolute:
- start_jul (list[int]): Element[0] receives the days since 1899 for the start time if status[0] == 0
- start_min (list[int]): Element[0] receives the minutes past midnight for the start time if status[0] == 0
- end_jul (list[int]): Element[0] receives the days since 1899 for the end time if status[0] == 0
- end_min (list[int]): Element[0] receives the minutes past midnight for the end time if status[0] == 0
- status (list[int]): Element[0] recieves
0if the time window string was successfully parsed,-1otherwise
Converts a time in hhmm format (integer or string) to minutes
Arguments:
- hm (int): The time to convert (e.g, '0730', 730)
Returns:
int: The equivalent minutes (e.g., 450)
Returns the weekday (1=Sunday -> 7=Saturday) for the specified date.
NOTE This differs from datetime.weekday() whch returns 0=Monday -> 6=Sunday.
Arguments:
date (Union[int, list[int]]): The date as:
int- number of days since 1899list- a list of at least 3 integers specifying the year, month and day
Returns:
int: The weekday (1=Sunday -> 7=Saturday)
Converts integers in a string to integer minutes
Arguments:
- hm (str): The string to collect integers from. Valid strings are:
- "0730"
- "730"
- "7 30"
- "0 7 3 0"
- "7H30M"
Returns:
int: The equivalent minutes (e.g., 450)
Increment or decrement time values by a specified amount and return the result
Arguments:
- values (list[int]): The time values (
[year, month, day, hour, minute, sec]) to increment/decrement. - increment_value (int): The number of granules to increment (>0) or decrement (<0)
- granularity (int): The granule size (SECOND_GRANULE, MINUTE_GRANULE, HOUR_GRANULE, or DAY_GRANULE)
Raises:
- HecTimeException: if values is less than six items in length
Returns:
list[int]: The incremented or decremented values
Increments a number of days since 1899 and minutes past midnight by a specified number of intervals of a specified size
Args:
- 6 Parameters:
- interval (Union[TimeSpan, timedelta, int]): - If integer, it is in minutes
- num_periods (int): - The number of intervals to increment
- start_julian (int): - The starting number of days since 1899
- start_minute (int): - The starting minutes past midnight
- end_julian (list[int]): - Element 0 receives the ending days since 1899
- end_minute (list[int]): - Element 0 receives the ending minutes past midnight
- 7 Parameters:
- interval (int): - The interval in minutes or days
- unit_flag (int): - A flag spcifying whether
intervalis in minutes (0) or days (1) - start_julian (int): - The starting number of days since 1899
- start_minute (int): - The starting minutes past midnight
- end_julian (list[int]): - Element 0 receives the ending days since 1899
- end_minute (list[int]): - Element 0 receives the ending minutes past midnight
Raises:
- HecTimeException: if invalid arguments are passed to the function
Return whether the specified year is a leap year
Arguments:
- y (int): The year
Returns:
bool: Whether the year is a leap year
Return whether specified granularity is valid
Arguments:
- value (int): The granularity value to test
Returns:
bool: Whether the value is one of
Return whether a specified time integer or time values are in the valid range for the specified granularity
Arguments:
- date_time (Union[int, list[int]]): The time integer or time values (
[year, month, day, hour, minute, second]) to check validity for - granularity (int): The granularity to check validity for
Returns:
bool: Whether the time integer or time values are in the valid range for the granularity
Returns the number of days since 31Dec1899 for a specified year, month, and day
Arguments:
- year (int): The year
- month (int): The month
- day (int): The day
Deprecated:
Returns:
int: The number of days sinc 31Dec1899
Populates year, month, and day arguments with the appropriate values for a specified number of days since 31Dec1899
Args:
- 2 args:
- jul (int): The number of days since 31Dec1899
- ymd (list[int]): A list of length >= 3 that receives the year, month, and day
- 4 args
- jul (int): The number of days since 31Dec1899
- year (list[int]): An integer list whose first value received the year
- month (list[int]): An integer list whose first value received the month
- day (list[int]): An integer list whose first value received the day
Deprecated:
Raises:
- HecTimeException: if invalid arguments are specified
Returns the date of the specified number of days since 31Dec1899 in the specified style
Arguments:
- julian (int): The number of days since 1899
- style (int): The style to return the date in. See
date()
Returns:
str: The date in the specified style
Populates year, month, and day arguments with the appropriate values for a specified number of days since 31Dec1899
Args:
- 2 args:
- jul (int): The number of days since 31Dec1899
- ymd (list[int]): A list of length >= 3 that receives the year, month, and day
- 4 args
- jul (int): The number of days since 31Dec1899
- year (list[int]): An integer list whose first value received the year
- month (list[int]): An integer list whose first value received the month
- day (list[int]): An integer list whose first value received the day
Raises:
- HecTimeException: if invalid arguments are specified
Returns the equivalent time integer (hhmm) for a specified minute count
Arguments:
- m (int): The minutes to convert (e.g., 450)
Returns:
int: The time equivalent in hhmm (e.g, 730)
Returns the equivalent time integer (hhmm) for a specified minute count and places the string representaion in HHMM format in the specified variable
Arguments:
- m (int): The minutes to convert (e.g., 450)
- hour_minutes (list[str]): Element 0 receives string equivalen in HHMM format (e.g., "0730")
Deprecated:
Returns:
int: The time equivalent in hhmm (e.g, 730)
Return the last month day for a specified year and month
Arguments:
- y (int): The year
- m (int): The month
Returns:
int: The last calendar day of the specified month
Returns the number of minutes past midnight for specified time values
Arguments:
- values (list[int]): The time values (
[year, month, day, hour, minute, second])
Raises:
- HecTimeException: If
valuesis less than six items in length
Returns:
int: The number of minutes past midnight
Returns the next year and for a specified year and month.
Arguments:
- y (int): The specified year
- m (int): The specified month
Returns:
tuple[int, int]: The next year and month
Returns the complete number of intervals between two times
Arguments:
- 5-parameter version
- interval (Union[Interval, int]): The interval to compute the number of. If an integer, must be the actual or characteristic minutes of a standard Interval object
- start_julian (int): The days since 1899 of the first time
- start_minute (int): The minutes past midnight of the first time
- end_julian (int): The days since 1899 of the second time
- end_minute (int): The minutes past midnight of the second time
- 6 parameter version
- interval (int): The number of minutes or days in the interval to compute the number of. Must be the actual or characteristic number of minutes (or equivalent days) of a standard Interval object
- unit_flag (int): 0 for interval in minutes, 1 for interval in days
- start_julian (int): The days since 1899 of the first time
- start_minute (int): The minutes past midnight of the first time
- end_julian (int): The days since 1899 of the second time
- end_minute (int): The minutes past midnight of the second time
Raises:
- HecTimeException: if the interval is not one of the standard intervals
Returns:
int: The number of complete intervals between the two times
Returns a valid date style for a specified input style
Arguments:
- style (int): The input date style
Returns:
int: The valid date style
Normalize a list of time values ([year, month, day, hour, minute, second]) in place.
Adjusts each element of the list to be in the valid range for a date/time value.
Arguments:
- values (list[int]): The values to normalize.
Raises:
- HecTimeException: if values is less that six items in length
Parse date/time strings of various formats into time values ([year, month, day, hour, minute, second] and an optional time zone string).
The string must contain at least year, month, day. Missing seconds, (minutes, seconds), or (hours, minutes, seconds) are set to zero.
For strings that cannot be parsed with this method, use HecTime.strptime()
Arguments:
- date_time_str (str): The date/time string
- include_tz (bool): Whether to include the time zone portion if date_time_str is in ISO-8601 format.
- If
True, the tuple returned will include the time zone string. Defaults to False
Raises:
- HecTimeException: if date_time_str cannot be parsed into at least year, month, and day
Returns:
tuple[list[int], Optional[str]]: *Position 0: The time values as parsed from the date/time string:
[year, month, day, hour, minute, second]*Position 1: The time zone string ifinclude_tz == Trueanddate_time_strhas a time zone portion, otherwise None
See Also:
Returns the previous year and for a specified year and month.
Arguments:
- y (int): The specified year
- m (int): The specified month
Returns:
tuple[int, int]: The previous year and month
Returns the number of seconds past midnight for specified time values
Arguments:
- values (list[int]): The time values (
[year, month, day, hour, minute, second])
Raises:
- HecTimeException: If
valuesis less than six items in length
Returns:
int: The number of seconds past midnight
Get the current time as days since 1899 and minutes or seconds past midnight and return in parameters, optionally in a specified time zone
Arguments:
- julian (list[int]): A list of length > 0 whose first value receives the current days since 1899
- time (list[int]): A list of length > 0 whose first value receives the current minutes or seconds past midnight
- time_in_minutes (Optional[bool]): Specifies whether to return the time in minutes (
True) or seconds (False) past midnight. Default is False - in_time_zone (Optional[str]): If present, specifies the time zone of the current time. The days and time values will be converted from this time zone to UTC
Return a copy of time values ([year, month, day, hour, minute, second]) with
[..., 24, 0, 0] changed to [..., 0, 0, 0] of the next day
Arguments:
- values (list[int]): The values to modify if ending in
[24, 0, 0]
Raises:
- HecTimeException: if values less than six items in length
Returns:
list[int]: A copy of the time values, modified if necessrary
Return a copy of time values ([year, month, day, hour, minute, second]) with
[..., 0, 0, 0] changed to [..., 24, 0, 0] of the previous day
Arguments:
- values (list[int]): The values to modify if ending in
[0, 0, 0]
Raises:
- HecTimeException: if values less than six items in length
Returns:
list[int]: A copy of the time values, modified if necessrary
Returns the number of days since 31Dec 1899 for a specified year, month, and day
Arguments:
- y (int): The year
- m (int): The month
- d (int): The day
- account_for_offset (bool) : (Default = True) Specifies whether to account for the missing date (31Dec0004). This should be True unless the function is called from an HecTime method which already accounts for it.
Returns:
int: The number of days since 31Dec1899
Returns the date in the specified style
Arguments:
- ymd (list[int]): The year, month, and day to format
- style (int): The style to use (see
HecTime.date()) - err (list[int]): Element 0 recieve
0on success and-1otherwise
Returns:
str: The date in the specified style, or None if err[0] == -1
Computes the offet into a standard interval and/or adjusts the specified time to be at the computed offset
NOTE: Unlike HecTime.adjust_to_interval_offset, any adjustments made will result
in the output time being earlier than the input time.
Arguments:
- julian (list[int]): On input, element 0 specifies the days since 1899 of the date On output,
element[0] recieves the adjusted days since 1899 if operation is
1or2 - minutes (list[int]): On input, element 0 specifies the minutes past midnight of the time. On output,
element[0] recieves the adjusted minutes past midnight if operation is
1or2 - interval (int): The interval used to compute the offset and/or adjust the time
- operation (int):
- 0: Compute the offset only (return in
offset[0]) - 1: Compute the offset (return in
offset[0]) and adjust the time to the offset (return injulian[0]andminutes[0]) - 2: adjust the time to the offset only (return in
julian[0]andminutes[0])
- 0: Compute the offset only (return in
- offset (list[int]): On output, element 0 receives the computed offset if operation is
0or1
Exception specific to the hectime module
Class to facilitate moving Jython scripts that use Java class hec.heclib.util.HecTime to Python
Implementation:
Compatibility with Java HecTime
This class replicates the capabilities of the Java
hec.heclib.util.HecTimeclass, and uses the same method names except the camel case names of the Java class have been renamed to snake case to match Python naming standards as shown in the following examples:
Java Method Name Python Method Name adjustToIntervalOffset() adjust_to_interval_offset() computeNumberIntervals() compute_number_intervals() Granularity
Like Java HecTime,
HecTimeobjects can be instaniated with different time granularities, with each granule specifying a second, minute, hour, or day. Specifically:
Granularity Integer Range Each Granule Specifies Date Range SECOND_GRANULARITY
= 10-2147483648
+2147483647Seconds after
01Jan1970, 00:00+1901-12-13T20:45:52
+2030-01-19T03:14:17MINUTE_GRANULARITY
= 11-2147483648
+2147483647Minutes after
31Dec1899, 00:00-2184-12-06T21:52
+5983-01-23T02:07HOUR_GRANULARITY
= 12-2147483648
+2147483647Hours after
31Dec1899, 00:00-243084-03-22T16
+246883-10-08T07DAY_GRANULARITY
= 13-2147483645
+2146789687Days after
31Dec1899-5877711-06-22
+5879610-07-10The default granularity is MINUTE_GRANULARITY, but this may be overridden when calling
HecTime().Chainable methods
Since, unlike Java, Python allows code to ignore the return value from functions and methods, many HecTime methods with a
voidreturn type in Java now return a modifiedHecTimeobject. This allows the chaining of methods together for simplify code. For example:t = HecTime() t.set_current() t.adjust_to_interval_offset(intvl, 0) t.increment(1, intvl)can now be coded as:
t = HecTime.now().adjust_to_interval_offset(intvl, 0).increment(1, intvl)although the previous style is still supported.
Compatibility with
datetimeThis class is written to be trivially convertable to/from
datetimeobjects and updatable viatimedeltaobjects. Likedatetimeobjects,HecTimeobjects are not time zone aware unless given time zone information. ForHecTimeobjects thelabel_as_time_zone()method is used for this purpose. Also likedatetimeobjects, using theastimezone()method causes the object to act as if it had been initialized with the local time zone.Initialization from a
datetimeobject is acccomplished viaht = HecTime(dt_obj). Retieval of adatetimeobject is accomplished viadt_obj = ht.datetime(). TheHecTime.label_as_time_zone(tz)accomplishes the same thing asdatetime.replace(tzinfo=tz), and theHecTime.astimezone(tz)accomplishes the same thing asdatetime.astimezone(tz)
datetimemethods, properties, and operators supported inHecTimeobjects are:
- Methods
now()(static method)astimezone(timezone)*strftime(format)strptime(date_time_str, format)__str__()(used inprint())- Properties
- Operators
+and+=-and-===and!=<and<=>and >=`*The
astimezone(timezone), method, like allHecTimemethods that take time zone will accept:
ZoneInfoobject- String (timezone name)
HecTimeobject (the object's time zone is used)datetimeobject (the object's time zone is used)Note: Compatibility with
datetimeas well as time zone support is only available onHecTimeobjects that are within thedatetimeobject range of 01Jan0001, 00:00 through 31Dec9999, 23:59. Also, time zone support is not provided forHecTimeobjects ofDAY_GRANULARITY.Addition, subtraction, and comparison operators
Integers,
HecTimeobjects,TimeSpanobjects,Intervalobjects,Durationobjects,timedeltaobjects, and specially formatted strings (see below) can be used on the right side of the+and+=operators. The result is always anotherHecTimeobject. AllowingHecTimeobjects to be added to each other breaks the similarity withdatetime, but is included to provide the functionality Java HecTime.Integers,
HecTimeobjects,datetimeobjects,TimeSpanobjects,Intervalobjects,Durationobjects,timedeltaobjects, and specially formatted strings (see below) can be used on the right side of the-or-=operators.
- The result is an
HecTimeobject when subtracting intgers,TimeSpanobjects,Intervalobjects,Durationobjects,timedeltaobjects and strings.- The result is a
TimeSpanobject when subtractingHecTimeobjects- The result is a
timedeltaobject when subtractingdatetimeobjectsIf the
HecTimeobject on the left side of any+,-,+=, or-=operator has a time zone attached and the right- side object is anIntervalhas theis_local_regularproperty of True, then addition and subtraction is performed with respect to the time zone of theHecTimeobject. For example if theHecTimeobject is at midnight in the US/Pacific time zone, then adding a local-regular interval of 2 hours will result in anHecTimeobject at 2 a.m. in the same time zone. The actual amount of time added with respect to UTC will be 1, 2, or 3 hours, depending on the day, month, and year.Adding and subtracting integers adds or subracts the number of granules in the object so the change may be in seconds, minutes, hours, or days, depending on the object's granularity.
Strings of the format used for the offset portion of relative time strings in
get_time_window()can be used in addition and subtraction operators. Examples
t - "1y"would return anHecTimeobject one year prior to thetobjectt += "3m-2d+1h"would increment thetobject forward 3 months, back 2 days and forward 1 hour.This precludes using ISO 8601 duration strings that have minutes or seconds components. To use these, create a
TimeSpanobject from the string for the addend
HecTimeobjects can be compared with each other or withdatetimeobjects using the standard operators (==,!=,<,<=,>,>=). Either type may be on either side of the operators.Use of properties
Many methods are deprecated and will generate deprecation warnings when used. Most have been replaced by direct read/write or read-only properties.
The
value(),year(),month(),day(),hour(),minute(), andsecond()methods are still supported but are accessed in a more pythonic way as read/write (value) or read-only (year,month,day,hour,minute,second) properties. There is no clean way to issue deprecation warning if these properties are accessed by their getter functions.
Initializes a newly-created HecTime object.
Arguments:
HecTime()initializes granularity toMINUTE_GRANULARITYand time toUNDEFINED_TIMEHecTime(granularity: int)initializes granularity togranularityand time toUNDEFINED_TIMEHecTime(values: Union[list[int],tuple[int,...]])initializes granularity toMINUTE_GRANULARITYand time tovaluesHecTime(other_hec_time: HecTime)initializes to the same granularity and time asother_hec_timeHecTime(dt: datetime)initializes granularity toMINUTE_GRANULARITYand time to the value ofdt.HecTime(date_time_str: str)initializes granularity toMINUTE_GRANULARITYand time to the results of parse_date_time_str(date_time_str)HecTime(time_int: int, granularity: int)initializes totime_intandgranularityHecTime(date_str: str, time_str: str)initializes granularity toMINUTE_GRANULARITYand time to the results of parse_date_time_str(date_str+" "+time_str)HecTime(date_str: str, time_str: str, granularity: int)initializes to the specified granularity and results of parse_date_time_str(date_str+" "+time_str)
Raises:
- HecTimeException: if invalid parameters are specified
Adds an number of granules or an HecTime to this object
Arguments:
- other (Union[int, "HecTime", TimeSpan, timedelta, str]): item to add
Deprecated:
Use the
+=operator instead
Returns:
HecTime: The modified object
Adds a number of days to the object
Arguments:
- days (int): the number of days to add.
Returns:
HecTime: The modified object
Adds a number of hours to the object
Arguments:
- hours (int): the number of hours to add.
Returns:
HecTime: The modified object
Adds a number of minutes to the object
Arguments:
- minutes (int): the number of minutes to add.
Returns:
HecTime: The modified object
Adds a number of seconds to the object
Arguments:
- seconds (int): the number of seconds to add.
Returns:
HecTime: The modified object
Adjusts this object to be at the specified offset past the specified interval.
NOTE: Unlike zofset The resulting time may be at, before, or after
the this object, but will always be in the interval that begins at or before this object.
To get the begninning of the interval that starts at or before this object, set offset_minutes to 0. To get the beginning of the next interval set offset_minutes be the same as interval_minutes.
Arguments:
- interval (Union[Interval, int]): The interval. If an integer, must be the actual or charactersitic minutes of a standard Interval
- offset_minutes (int): The offset into the interval in minutes (0..interval)
Returns:
The adjusted object
Raises:
- HecTimeException: if offset it out of range for interval
Returns an integer comparison with another HecTime object
Arguments:
- other (HecTime): The other HecTime object
Returns:
int:
- -1 if this object < other
- 0 if this object == other
- 1 if this object > other
Not supported in this implementation
Returns the number of complete intervals between this object and another specified HecTime object
Arguments:
- other (HecTime): The other time to compute the number of intervals to
interval (Union[int, timedelta]): The interval size to compute the number of intervals for.
int- the minutes in a standard intervaltimedelta- If equivalent to a standard interval, the same result as specifying the equivalent integer is returned. Otherwise the both HecTime objects are converted to datetime objects and the number of intervals is computed as `((other.datetime - self.datetime) / timesdelta')
Raises:
- HecTimeException: if
intervalis a non-standard integer or if it is a nonstandard timedelta and either of this object orotheris not convertable to a datetime object
Returns:
int: The number of complete intervals between this time and the other time.
Converts this object from one time zone to another, optionally specifyintg that the target time zone does not observe Daylight Saving Time (DST). Only for HecTime objects convertable to datetime objects (between 01Jan0001, 00:00 and 31Dec9999, 23:59).
NOTE: The Java signatures for this method that operate on and return a copy of the HecTime
object are not supported in this implementation. The astimezone() method can be used for that purpose.
Arguments:
- from_time_zone (Union[ZoneInfo, str]): The time zone to convert from
- to_time_zone (Union[ZoneInfo, str]): The target time zone
- respect_daylight_saving (Optional[bool]): Specifies whether the target time zone.
should observe DST. Defaults to True.
- If
True, the target time zone is used as specified - If
Falseand the specified target time zone observes DST, then a time zone is found that has the same UTC offset as the specified target time zone but does not observe DST.
- If
Returns:
HecTime: The modified object
Raises:
- HecTimeException: - If
respect_daylight_savingisTrue,to_time_zoneobserves DST and no equivalent time zone could be found that does not observer DST- If this object is not convertable to a datetime object
Returns a copy of this object at the spcified time zone
Arguments:
- time_zone (Optional[Union["HecTime", datetime, ZoneInfo, timezone, str]]): The target time zone or object containg the target time zone.
- Use
Noneto remove time zone information without time conversion. - Use
"local"to specify the system time zone.
- Use
- on_tz_not_set (int, optional): Specifies behavior if this object has no time zone attached. Defaults to 1.
0: Quietly behave as if this object had the local time zone attached.1: (default) Same as0, but issue a warning.2: Raise an exception preventing objectes with out time zones attached from using this method.
Returns:
HecTime: A copy of this object at the specified time zone
Returns the date in the specified style
| Base date styles | |||
|---|---|---|---|
| 0: June 2, 1985 | 10: June 2, 85 | 100: JUNE 2, 1985 | 110: JUNE 2, 85 |
| 1: Jun 2, 1985 | 11: Jun 2, 85 | 101: JUN 2, 1985 | 111: JUN 2, 85 |
| 2: 2 June 1985 | 12: 2 June 85 | 102: 2 JUNE 1985 | 112: 2 JUN 85 |
| 3: June 1985 | 13: June 85 | 103: JUNE 1985 | 113: JUNE 85 |
| 4: 02Jun1985 | 14: 02Jun85 | 104: 02JUN1985 | 114: 02JUN85 |
| 5: 2Jun1985 | 15: 2Jun85 | 105: 2JUN1985 | 115: 2JUN85 |
| 6: Jun1985 | 16: Jun85 | 106: JUN1985 | 116: JUN85 |
| 7: 02 Jun 1985 | 17: 02 Jun 85 | 107: 02 JUN 1985 | 117: 02 JUN 85 |
| 8: 2 Jun 1985 | 18: 2 Jun 85 | 108: 2 JUN 1985 | 118: 2 JUN 85 |
| 9: Jun 1985 | 19: Jun 85 | 109: JUN 1985 | 119: JUN 85 |
| Extended date styles | |||
| -1: 6/2/85 | -11: 06/02/85 | -101: 6/2/1985 | -111: 06/02/1985 |
| -2: 6-2-85 | -12: 06-02-85 | -102: 6-2-1985 | -112: 06-02-1985 |
| -13: 1985-06-02 | |||
NOTE that years that overflow four digits will not be truncated if using a style that shows four digits in the table (styles 0..9, 100..109, -113..-101 and -13). Other formats will continue to show only the last two digits of the year. In all cases a negative sign will be prepended to the year for negative years (whether two digits or more are shown).
Arguments:
- style (Optional[int]): The date style to use. If not specified the
default_date_styleproperty is used
Returns:
str: The formatted date
Returns a string representing the date and time in the specified style.
Arguments:
- style (Optional[int]): The date style to use. If not specified the
default_date_styleproperty is used
Returns:
str: The formatted date and time. The date is generated using the style parameter (see
date), which is separated from the time portion (with colons) (seetime) by a comma and space
The object's current date and time string using the default_date_style
Operations:
Read
Returns the day of week (1 = Sunday -> 7 = Saturday) for this object.
NOTE: This differs from datetime.weekday() whch returns 0=Monday -> 6=Sunday.
Returns:
int: The day of week (1 = Sunday -> 7 = Saturday)
Returns the day of the year of this object (01Jan = 1)
Returns:
Optional[int]: The day of the year
Returns whether this object is equivalent to another
Arguments:
- other (Union["HecTime", datetime]): The object to compare to
Deprrecated:
Use
==operator instead
Returns:
bool: The result of the comparison
Returns the default date style
Deprecated:
Use default_date_style property instead
Returns int: The default date style
Returns the number of minutes that the current object is after the top of the most recent standard interval
Arguments:
- interval Union[Interval, int]: The interval to determine the offset into. If int, then the value is minutes.
Raises:
- HecTimeException: if the interval is not a standard interval
Returns:
Optional[int]: The number of minutes into the interval
Returns the time of this object in ISO 8601 format.
Returns:
str: The time of this object in ISO 8601 format
Returns the time of this object as (days since 1899) * 1400 + (minutes past midnight), optionally offsetting by a time zone
Arguments:
- time_zone_offset (Optional[Union[int, ZoneInfo]]): if
int, the number of minutes behind UTC (positive for western longitudes)
Returns:
int: The time in minutes
Retrieves whether midnight is shown as hour 0 instead of hour 24 of the previous day
Deprecated:
Use midnight_as_2400 property instead
Returns:
bool:
Trueif midnight is shown as hour 0,Falseif midnight is shown as hour 24
Returns a string representing the time portion
- with_colons = True (default),
[..., 6, 8, 23]is retuned is06:08:23 - with_colons = False,
[..., 6, 8, 23]is retuned is0608
Arguments:
- with_colons (Optional[bool]): Specifies with or without colons. Defaults to
True.
Deprecated:
use .HecTime.time">time method instead
Returns:
str: The time portion string with colons (hour, minute, and second), or without colons (hour, minute only))
Returns the granularity of this object
Deprecated:
Use granularity property instead
Returns:
int: The granularity
Returns the time of this object in milliseconds into of the Unix Epoch (01Jan1970 00:00:00 UTC).
Note that is the standard time value used in Java as well as 1000.0 times the standard time
value used in python (e.g., time.time() or datetime.timestamp())
Arguments:
- time_zone_offset (Optional[Union[int, ZoneInfo]]): if
int, the number of minutes behind UTC (positive for western longitudes). If not specified, the milliseconds returned will be as if this object is in UTC
Returns:
Optional[int]: None if this object is not defined., otherwise the milliseconds of the current time from the beginning of the Unix Epoch
Returns the time of this object in ISO 8601 format.
Deprecated:
Use get_iso_8601_date_time instead
Raises:
- HecTimeException: if time_zone_offset is specifed but is not an integer or ZoneInfo object,
- or is a ZoneInfo object and no UTC offset could be determined from it
Returns:
str: The time of this object in ISO 8601 format
The object's current granularity.
Operations:
Read/Write
Returns:
int: The granularity
Returns whether this object is greater than (later than) another HecTime object
Arguments:
- other (HecTime): The other object to compare to
Deprecated:
Use the the
>operator instead.
Returns:
bool: Whether this object is greater than the other
Returns whether this object is greater than (later than) or equal to (same time as) another HecTime object
Arguments:
- other (HecTime): The other object to compare to
Deprecated:
Use the the
>=operator instead.
Returns:
bool: Whether this object is greater than or equal to the other
Returns the time portion in HHMM format or "" if this object is undefined
Returns:
str: The time portion in HHMM format or "" if this object is undefined
Returns the object's hour, minute, and second in the spefied parameters
Arguments:
- hours (list[int]): Element 0 recieves the hour
- minutes (list[int]): Element 0 recieves the minute
- seconds (list[int]): Element 0 receives the second
Increments this object by a specified number of intervals.
For month-based intervals ("Tri-Month", "Semi-Month", "1Month", "1Year"), if the date
of the current object is the last day of a month, the resulting date will be the last day of the month
or sub-month (days 10 or 20 for "Tri-Month" and day 15 for "Semi-Month"), as shown:
| Start Time | Count | Interval | Result |
|---|---|---|---|
| 28Feb2023, 01:00 | 1 | "Tri-Month" | 10Mar2023, 01:00 |
| 28Feb2023, 01:00 | 2 | "Tri-Month" | 20Mar2023, 01:00 |
| 28Feb2023, 01:00 | 3 | "Tri-Month" | 31Mar2023, 01:00 |
| 28Feb2024, 01:00 | 1 | "Tri-Month" | 08Mar2023, 01:00 |
| 28Feb2024, 01:00 | 2 | "Tri-Month" | 18Mar2023, 01:00 |
| 28Feb2024, 01:00 | 3 | "Tri-Month" | 28Mar2023, 01:00 |
Note that this method produces results that differ from the Java HecTime.increment() method where
the Java code produces incorrect results, as in the following examples (all such discrepancies are
limited to "Tri-Month", "Semi-Month", and "1Month":
| Start Time | Count | Interval | Correct Result | Java HecTime Result |
|---|---|---|---|---|
| 29Jan2023, 01:00 | 1 | "1Month" | 28Feb2023, 01:00 | 01Mar2023, 01:00 |
| 09Feb2024, 01:00 | 2 | "Tri-Month" | 29Feb2024, 01:00 | 09Mar2024, 01:00 |
| 28Feb2024, 01:00 | 2 | "Semi-Month" | 28Mar2024, 01:00 | 31Mar2024, 01:00 |
Arguments:
- count (int): The number of intervals to increment
- interval (Union[Interval, TimeSpan, timedelta, int]): The interval to increment by. If int:
- interpreted as a number of minutes
- for standard intervals:
- should be actual minutes for intervals <= 1Week
- should characteristic minutes for intervals > 1Week
Returns:
HecTime: The incremented object
Increments this object by a specified number of intervals, which are specified in seconds
Arguments:
- count (int): The number of intervals to increment
- interval (int): The size of the interval in seconds. The behavior depends on whether the interval is < 60:
< 60- the object is incremented by (count * interval) seconds>= 60- The object is incremented by (count * interval // 60) minutes
Returns:
HecTime: The incremented object
Returns the date of the current object as YYMMDD format
Returns:
str: The date in YYMMDD format
Returns the time of the current object as HHMMSS format
Returns:
str: The date in HHMMSS format
Attaches the specified time zone to this object. Does not change the time
Arguments:
- time_zone (Optional[Union["HecTime", datetime, ZoneInfo, timezone, str]]): The time zone to attach or object containing that time zone.
Use
"local"to specify the system time zone. - on_already_set (int, optional): Specifies action to take if a different time zone is already
attached. Defaults to 1.
0: Quietly attach the new time zone1: (default) Issue a warning about attaching a different time zone2: Raises an exception
Raises:
- HecTimeException: if a different time zone is already attached and
on_already_set== 2
Returns:
HecTime: The updated object
Returns the number of days since 31Dec8199 for this object
Returns:
int: The number of days since 31Dec1899
Returns whether this object is less than (earlier than) another HecTime object
Arguments:
- other (HecTime): The other HecTime object
Deprecated:
Use the
<operator instead
Returns:
bool: Whether this object is less than the other object
Returns whether this object is less than (earlier than) another or equal to (same time as) HecTime object
Arguments:
- other (HecTime): The other HecTime object
Deprecated:
Use the
<=operator instead
Returns:
bool: Whether this object is less than or equal to the other object
The object's current setting of whether to show midnight as hour 24 (default) or not.
Operations:
Read/Write
Returns the number of minutes past midnight for this object
Returns:
int: the number of minutes past midnight
Returns whether this object is not equivalent to another
Arguments:
- other (Union["HecTime", datetime]): The object to compare to
Deprrecated:
Use
!=operator instead
Returns:
bool: The result of the comparison
Returns a new HecTime object initialized to the current system time and specified or default granularity
Arguments:
- granularity (int, optional): The granularity of the new object. Defaults to MINUTE_GRANULARITY.
Returns:
HecTime: The newly created object
Returns the number of seconds past midnight for this object
Returns:
int: the number of seconds past midnight
Set the object to a specified date/time. Valid parameters are:
set(time_int: int)sets the time to the value oftime_intfor the current granularityset(date_time_str: str)sets the time to the results of .parse_date_time_str">parse_date_time_str(date_time_str)set(dt: datetime)sets the time to the value ofdtset(values: Union[list[int],tuple[int,...]])sets the time tovaluesset(other_hectime: HecTime)sets the time and granularity to be the same asother_hectimeset(date_str: str, time_str: str)sets the time to the results of .parse_date_time_str">parse_date_time_str(date_str+" "+time_str)
Returns:
int:
0if date/time is successfully set, otherwise non-zero
See Also:
Sets the date portion only from a string
Arguments:
- date_str (str): The date string. Any time portion is ignored
Returns:
int:
0on success or-1on failure
Sets the default date style
Arguments:
- style (int): The default date style
Deprecated:
Use default_date_style property instead
Sets the date portion from the number of days since 1899, and optionally the time portion
Arguments:
- julian (int): The number of days since 1899
- minutes_since_midnight (Optional[int]): The number of minutes past midnight for the time portion. Defaults to None.
- seconds_since_midnight (Optional[int]): The number of seconds past the minute for the time portion. Defaults to None.
Returns:
HecTime: The modified object
Set the date and time portions of this object from the number of minutes since 1899
Arguments:
- total_minutes (int): The number of minutes since 1899
- time_zone_offset (Optional[Union[int, "ZoneInfo"]]): The time zone to represent this object in. Defaults to None.
If
int, the number of minutes behind UTC (positive for western longitudes)
Returns:
HecTime: The modified object
Raises:
- HecTimeException: if
time_zone_offsetis not an integer orZoneInfoobject, or if the UTC offset cannot be determed for theZoneInfoobject
Sets the date and time portions of this object from the number seconds since 1970-01-01T00:00:00Z
Arguments:
- total_seconds (int): The number of seconds since 1970-01-01T00:00:00Z (same as Python timestamps and seconds of Unix Epoch)
Returns:
HecTime: The modified object
Set the time portion of this object from a time string with or without the date portion
Arguments:
- time_str (str): the time string
Returns:
int:
0on success or-1if the time string cannot be parsed
Sets the granularity, keeping the existing time values if possible
Arguments:
- granularity (int): The new granularity
Deprecated:
Use granularity property instead
Returns:
HecTime: The modified object
Not supported in this implementation
Sets the date and time portions of this object from the number milliseconds since 1970-01-01T00:00:00Z
Arguments:
- milliseconds (int): The number of seconds since 1970-01-01T00:00:00Z (same as Java milliseconds and milliseconds of Unix Epoch)
- time_zone_offset (Optional[Union[int, "ZoneInfo"]]): The time zone to represent this object in. Defaults to None.
If
int, the number of minutes behind UTC (positive for western longitudes)
Returns:
HecTime: The modified object
Sets the date portion from a year, month, and day, and optioally the time portion from minutes past midnight
Arguments:
- year (int): The year
- month (int): The month
- day (int): The day
- minutes_since_midnight (Optional[int]): The minutes past midnight
Returns:
HecTime: The modified object
Sets whether to show midnight as hour 0 instead of hour 24 of the previous day
Arguments:
- state (bool): Whether to show midnight as hour 0 instead of hour 24 of the previous day
Deprecated:
Use midnight_as_2400 property instead
Returns:
HecTime: The modified object
Returns a string representing the date and time in the specified format.
Arguments:
- format (str): The format string. Format specfics can be found here.
Returns:
str: The formatted date and time
See Also:
Sets this object from a string representation and a matching format.
Arguments:
- date_time_str (str): The string to parse.
- format (str): The format describing the string. Format specfics can be found here.
Returns:
HecTime: The object updated from the string representation and formt.
See Also:
Subtracts an integer number of granules or HecTime object from this one
Arguments:
- other (Union[int, "HecTime", TimeSpan, timedelta, str]): item to subtract
Deprecated:
Use the
-=operator instead
Returns:
HecTime: The modified object
Subtracts a number of days from the object
Arguments:
- days (int): the number of days to subtract.
Returns:
HecTime: The modified object
Subtracts a number of hours fram the object
Arguments:
- hours (int): the number of hours to subtract.
Returns:
HecTime: The modified object
Subtracts a number of minutes from the object
Arguments:
- minutes (int): the number of minutes to subtract.
Returns:
HecTime: The modified object
Subtracts a number of seconds from the object
Arguments:
- seconds (int): the number of seconds to subtract.
Returns:
HecTime: The modified object
Returns a string representing the time portion
- with_colons = True (default),
[..., 6, 8, 23]is retuned is06:08:23 - with_colons = False,
[..., 6, 8, 23]is retuned is0608
Arguments:
- with_colons (Optional[bool]): Specifies with or without colons. Defaults to
True.
Returns:
str: The time portion string with colons (hour, minute, and second), or without colons (hour, minute only))
Returns the granularity of this object
Deprecated:
Use granularity property instead
Returns:
int: The granularity
Not supported in this implementation
The object's current time values ([year, month, day, hour, minute, second]).
This property is None when the value property is UNDEFINED_TIME
Operations:
Read/Write