ladybug.dt module

Ladybug datetime.

class ladybug.dt.Date(month=1, day=1, leap_year=False)[source]

Bases: date

Ladybug Date.

Parameters:
  • month – A value for month between 1-12. Default: 1.

  • day – A value for day between 1-31. Default: 1.

  • leap_year – A boolean to indicate if date is for a leap year. Default: False.

Properties:
  • day

  • doy

  • leap_year

  • month

  • year

ToString()[source]

Overwrite .NET ToString.

ctime()

Return ctime() style string.

classmethod from_array(date_array)[source]

Create Ladybug Date from am array of integers.

Parameters:

datetime_array – An array of 2 integers (and optional leap_year boolean) ordered as follows: (month, day, leap_year)

classmethod from_date_string(date_string, leap_year=False)[source]

Create Ladybug Date from a Date string.

Usage:

dt = Date.from_date_string("31 Dec")
classmethod from_dict(data)[source]

Create date from a dictionary.

Parameters:

data – A python dictionary in the following format

{
'month': 1  # A value for month between 1-12. (Default: 1)
'day': 1  # A value for day between 1-31. (Default: 1)
}
classmethod from_doy(doy, leap_year=False)[source]

Create Ladybug Date from an day of the year.

Parameters:

doy – An int value 0 <= and < 366

fromisocalendar()

int, int, int -> Construct a date from the ISO year, week number and weekday.

This is the inverse of the date.isocalendar() function

fromisoformat()

str -> Construct a date from a string in ISO 8601 format.

fromordinal()

int -> date corresponding to a proleptic Gregorian ordinal.

fromtimestamp()

Create a date from a POSIX timestamp.

The timestamp is a number, e.g. created via time.time(), that is interpreted as local time.

isocalendar()

Return a named tuple containing ISO year, week number, and weekday.

isoformat()

Return string in ISO 8601 format, YYYY-MM-DD.

isoweekday()

Return the day of the week represented by the date. Monday == 1 … Sunday == 7

replace()

Return date with new specified fields.

strftime()

format -> strftime() style string.

timetuple()

Return time tuple, compatible with time.localtime().

to_array()[source]

Return date as an array of values.

to_dict()[source]

Get date as a dictionary.

today()

Current date or datetime: same as self.__class__.fromtimestamp(time.time()).

toordinal()

Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.

weekday()

Return the day of the week represented by the date. Monday == 0 … Sunday == 6

day
property doy

Calculate day of the year for this date.

property leap_year

Boolean to note whether Date belongs to a leap year or not.

max = datetime.date(9999, 12, 31)
min = datetime.date(1, 1, 1)
month
resolution = datetime.timedelta(days=1)
year
class ladybug.dt.DateTime(month=1, day=1, hour=0, minute=0, leap_year=False)[source]

Bases: datetime

Create Ladybug Date time.

Parameters:
  • month – A value for month between 1-12 (Default: 1).

  • day – A value for day between 1-31 (Default: 1).

  • hour – A value for hour between 0-23 (Default: 0).

  • minute – A value for month between 0-59 (Default: 0).

  • leap_year – A boolean to indicate if datetime is for a leap year (Default: False).

Properties:
  • month

  • day

  • hour

  • leap_year

  • doy

  • hoy

  • int_hoy

  • minute

  • moy

  • float_hour

  • tzinfo

  • year

ToString()[source]

Overwrite .NET ToString.

add_hour(hour)[source]

Create a new DateTime from this time + timedelta.

Parameters:

hour – A float value in hours (e.g. .5 = half an hour)

add_minute(minute)[source]

Create a new DateTime after the minutes are added.

Parameters:

minute – An integer value for minutes.

astimezone()

tz -> convert to local time in new timezone tz

combine()

date, time -> datetime with same date and time fields

ctime()

Return ctime() style string.

dst()

Return self.tzinfo.dst(self).

classmethod from_array(datetime_array)[source]

Create Ladybug DateTime from am array of integers.

Parameters:

datetime_array – An array of 4 integers (and optional leap_year boolean) ordered as follows: (month, day, hour, minute, leap_year)

classmethod from_date_and_time(date, time)[source]

Create Ladybug DateTime from a Date and a Time object.

Parameters:
  • date – A ladybug Date object.

  • time – A ladybug Time object.

classmethod from_date_time_string(datetime_string, leap_year=False)[source]

Create Ladybug DateTime from a DateTime string.

Parameters:
  • datetime_string – A text string representing a DateTime (ie. “21 Jun 12:00”)

  • leap_year – Boolean to note whether the Date Time is a part of a leap year. Default: False.

Usage:

dt = DateTime.from_date_time_string("31 Dec 12:00")
classmethod from_dict(data)[source]

Create datetime from a dictionary.

Parameters:

data – A python dictionary in the following format

{
'month': 1  #A value for month between 1-12. (Default: 1)
'day': 1  # A value for day between 1-31. (Default: 1)
'hour': 0  # A value for hour between 0-23. (Default: 0)
'minute': 0  # A value for month between 0-59. (Default: 0)
}
classmethod from_first_hour(leap_year=False)[source]

Create Ladybug DateTime for the first hour of the year.

Parameters:

leap_year – Boolean to note whether the Date Time is a part of a leap year. Default: False.

classmethod from_hoy(hoy, leap_year=False)[source]

Create Ladybug Datetime from an hour of the year.

Parameters:
  • hoy – A float value 0 <= and < 8760

  • leap_year – Boolean to note whether the Date Time is a part of a leap year. Default: False.

classmethod from_last_hour(leap_year=False)[source]

Create Ladybug DateTime for the last hour of the year.

Parameters:

leap_year – Boolean to note whether the Date Time is a part of a leap year. Default: False.

classmethod from_moy(moy, leap_year=False)[source]

Create Ladybug Datetime from a minute of the year.

Parameters:
  • moy – An integer value 0 <= and < 525600

  • leap_year – Boolean to note whether the Date Time is a part of a leap year. Default: False.

fromisocalendar()

int, int, int -> Construct a date from the ISO year, week number and weekday.

This is the inverse of the date.isocalendar() function

fromisoformat()

string -> datetime from a string in most ISO 8601 formats

fromordinal()

int -> date corresponding to a proleptic Gregorian ordinal.

fromtimestamp()

timestamp[, tz] -> tz’s local time from POSIX timestamp.

isocalendar()

Return a named tuple containing ISO year, week number, and weekday.

isoformat()

[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. The optional argument timespec specifies the number of additional terms of the time to include. Valid options are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’.

isoweekday()

Return the day of the week represented by the date. Monday == 1 … Sunday == 7

now()

Returns new datetime object representing current time local to tz.

tz

Timezone object.

If no tz is specified, uses local timezone.

replace()

Return datetime with new specified fields.

strftime()

format -> strftime() style string.

strptime()

string, format -> new datetime parsed from a string (like time.strptime()).

sub_hour(hour)[source]

Create a new DateTime from this time - timedelta.

Parameters:

hour – A float value in hours (e.g. .5 is half an hour and 2 is two hours).

sub_minute(minute)[source]

Create a new DateTime after the minutes are subtracted.

Parameters:

minute – An integer value for the number of minutes.

timestamp()

Return POSIX timestamp as float.

timetuple()

Return time tuple, compatible with time.localtime().

timetz()

Return time object with same time and tzinfo.

to_array()[source]

Return datetime as an array of values.

to_dict()[source]

Get datetime as a dictionary.

to_simple_string(separator='_')[source]

Return a simplified string.

today()

Current date or datetime: same as self.__class__.fromtimestamp(time.time()).

toordinal()

Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.

tzname()

Return self.tzinfo.tzname(self).

utcfromtimestamp()

Construct a naive UTC datetime from a POSIX timestamp.

utcnow()

Return a new datetime representing UTC day and time.

utcoffset()

Return self.tzinfo.utcoffset(self).

utctimetuple()

Return UTC time tuple, compatible with time.localtime().

weekday()

Return the day of the week represented by the date. Monday == 0 … Sunday == 6

property date

Get a Date object associated with this DateTime.

day
property doy

Calculate day of the year for this date time.

property float_hour
Type:

Get hour and minute as a float value, e.g. 6.25 for 6

fold
hour
property hoy

Calculate hour of the year for this date time.

property int_hoy

Calculate hour of the year for this date time as an integer.

This output assumes the minute is 0.

property leap_year

Boolean to note whether DateTime belongs to a leap year or not.

max = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)
microsecond
min = datetime.datetime(1, 1, 1, 0, 0)
minute
month
property moy

Calculate minute of the year for this date time.

resolution = datetime.timedelta(microseconds=1)
second
property time

Get a Time object associated with this DateTime.

tzinfo
year
class ladybug.dt.Time(hour=0, minute=0)[source]

Bases: time

Create Ladybug Time.

Parameters:
  • hour – A value for hour between 0-23 (Default: 0).

  • minute – A value for month between 0-59 (Default: 0).

Properties:
  • hour

  • minute

  • mod

  • second

  • tzinfo

ToString()[source]

Overwrite .NET ToString.

dst()

Return self.tzinfo.dst(self).

classmethod from_array(time_array)[source]

Create Ladybug Time from am array of integers.

Parameters:

datetime_array – An array of 2 integers ordered as follows: (hour, minute)

classmethod from_dict(data)[source]

Create time from a dictionary.

Parameters:

data – A python dictionary in the following format

{
'hour': 0  # A value for hour between 0-23. (Default: 0)
'minute': 0  # A value for month between 0-59. (Default: 0)
}
classmethod from_mod(mod)[source]

Create Ladybug Time from a minute of the day.

Parameters:

mod – An int value 0 <= and < 1440

classmethod from_time_string(time_string, leap_year=False)[source]

Create Ladybug Time from a Time string.

Usage:

dt = Time.from_time_string("12:00")
fromisoformat()

string -> time from a string in ISO 8601 format

isoformat()

Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].

The optional argument timespec specifies the number of additional terms of the time to include. Valid options are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’ and ‘microseconds’.

replace()

Return time with new specified fields.

strftime()

format -> strftime() style string.

to_array()[source]

Return time as an array of values.

to_dict()[source]

Get time as a dictionary.

tzname()

Return self.tzinfo.tzname(self).

utcoffset()

Return self.tzinfo.utcoffset(self).

property float_hour
Type:

Get hour and minute as a float value, e.g. 6.25 for 6

fold
hour
max = datetime.time(23, 59, 59, 999999)
microsecond
min = datetime.time(0, 0)
minute
property mod

Calculate minute of the day for this time.

resolution = datetime.timedelta(microseconds=1)
second
tzinfo