Class DateUtil
- class ooodev.utils.date_time_util.DateUtil[source]
Date and time utilities
- classmethod calc_to_date(value)[source]
Get date from calc value
- Parameters:
value (float) – Float value from cell
- Returns:
Date object, the current local date.
- Return type:
datetime.date
See also
- classmethod date(year, month, day)[source]
Get date from year, month, day
- Parameters:
year (int) – Year
month (int) – Month
day (int) – Day
- Returns:
date object
- Return type:
datetime.date
See also
- static date_from_number(value)[source]
Converts a float value to corresponding datetime instance.
- Parameters:
value (Number) – number to convert to date and time
- Raises:
TypeError – If value is not correct type.
- Returns:
Date time instance on success; Otherwise, None
- Return type:
datetime
- static date_time_str(dt)[source]
Returns a formatted date and time as string.
Method is Lo Instance Safe for use with multiple documents.
- Parameters:
dt (datetime) – date time
- Returns:
formatted date string such as
Jun 05, 2022 20:15
- Return type:
str
- static date_to_number(date)[source]
Converts a date or datetime instance to a corresponding float value.
- Parameters:
date (datetime | date) – date or date time to convert to float
- Raises:
TypeError – If date is not a correct type.
- Returns:
date as float on success; Otherwise, None
- Return type:
float
- classmethod date_to_uno_date(date)[source]
Converts a date representation into the com.sun.star.util.DateTime date format Acceptable boundaries:
year >= 1900
and<= 32767
- Parameters:
date (Any) –
datetime.datetime
,datetime.date
,datetime.time
,float
(time.time) ortime.struct_time
- Returns:
A
com.sun.star.util.Time
if conversion was successful; Otherwise,date
- Return type:
Date
- static date_to_uno_date_time(date)[source]
Converts a date representation into the com.sun.star.util.DateTime date format Acceptable boundaries:
year >= 1900
and<= 32767
- Parameters:
date (Any) –
datetime.datetime
,datetime.date
,datetime.time
,float
(time.time) ortime.struct_time
- Returns:
A
com.sun.star.util.DateTime
if conversion was successful; Otherwise,date
- Return type:
DateTime
- classmethod datetime(year, month, day, hours, minutes, seconds)[source]
Get datetime from year, month, day, hours, minutes and seconds
- Parameters:
year (int) – Year
month (int) – Month
day (int) – Day
hours (int) – Hours
minutes (int) – Minutes
seconds (int) – Seconds
- Returns:
Datetime object
- Return type:
datetime.datetime
- classmethod end(get_seconds=True)[source]
End counter
- Parameters:
get_seconds (bool) – If return value in total seconds.
- Returns:
Return the timedelta or total seconds.
- Return type:
timedelta | int
- classmethod str_date_time(uno_dt)[source]
Returns a formatted date and time as string.
Method is Lo Instance Safe for use with multiple documents.
- Parameters:
uno_dt (datetime) – date time
- Returns:
formatted date string such as
Jun 05, 2022 20:15
or empty string ifuno_dt
is null.- Return type:
str
- classmethod time(hours, minutes, seconds)[source]
Get time from hour, minutes, seconds
- Parameters:
hours (int) – Hours
minutes (int) – Minutes
seconds (int) – Seconds
- Returns:
Time object
- Return type:
datetime.time
- static time_from_number(value)[source]
Converts a float value to corresponding time instance.
Only Hours, Minutes and seconds are are used in conversion.
- Parameters:
value (Number) – Number such a float or int to convert
- Raises:
TypeError – If value is not correct type.
- Returns:
Value as time on success; Otherwise, None
- Return type:
time | None
- static time_stamp(tz=None)[source]
Gets a time stamp string
- Parameters:
tz (timezone | None, optional) – TimeZone
- Returns:
Formatted timestamp such as
2022-06-19 17:12:38
- Return type:
str
- static time_to_number(time)[source]
Converts a time instance to a corresponding float value.
Only Hours, Minutes and seconds are are used in conversion.
- Parameters:
time (datetime.time) – time to convert
- Raises:
TypeError – If date is not a correct type.
- Returns:
time as float on success; Otherwise, None
- Return type:
float
- classmethod time_to_uno_time(time)[source]
Converts a python time to UNO Time struct instance
- Parameters:
time (UnoTime) – Python time
- Returns:
UNO Time struct
- Return type:
Time
- static uno_date_to_date(uno_date)[source]
Converts a uno Date struct to a datetime instance
- Parameters:
uno_date (UnoDate) – uno Date struct
- Returns:
Python DateTime
- Return type:
datetime.datetime
- static uno_dt_to_dt(uno_dt)[source]
Converts a uno DateTime struct to a datetime instance.
Method is Lo Instance Safe for use with multiple documents.
- Parameters:
uno_dt (UnoDateTime) – uno Datetime struct
- Returns:
Python DateTime
- Return type:
datetime.datetime
- static uno_time_to_date_time(uno_time)[source]
Converts a uno Time struct to a datetime instance
- Parameters:
uno_time (UnoTime) – uno Time struct
- Returns:
Python DateTime
- Return type:
datetime.datetime
- static uno_time_to_time(uno_time)[source]
Converts a uno Time struct to a time instance
- Parameters:
uno_time (UnoTime) – uno Time struct
- Returns:
Python Time
- Return type:
datetime.time
- epoch
- now = datetime.datetime(2024, 10, 27, 23, 5, 20)
- now_time
- today = datetime.date(2024, 10, 27)