degreedays.time¶
Classes for working with dates and date-ranges in the context of degree days and energy data.
Class summaries¶
Defines the day of the week, with class constants to represent all 7 (Monday to Sunday). |
|
Specifies a range of one or more days e.g. 2020-01-01 to 2020-12-31. |
|
A chronologically-ordered set of one or more non-overlapping |
|
Specifies a definition of "months" that begin on a specified day of the month (e.g. 1 for calendar months). |
|
Specifies a definition of "years" that begin on a specified day of the year (e.g. January 1st for calendar years). |
degreedays.time¶
Classes for working with dates and date-ranges in the context of degree days and energy data.
- class degreedays.time.DayOfWeek(index: int)¶
Defines the day of the week, with class constants to represent all 7 (Monday to Sunday).
- FRIDAY: DayOfWeek¶
Representing Friday, with a str value of
'Friday', anindexof 4, and anisoIndexof 5.Access via:
DayOfWeek.FRIDAY
- MONDAY: DayOfWeek¶
Representing Monday, with a str value of
'Monday', anindexof 0, and anisoIndexof 1.Access via:
DayOfWeek.MONDAY
- SATURDAY: DayOfWeek¶
Representing Saturday, with a str value of
'Saturday', anindexof 5, and anisoIndexof 6.Access via:
DayOfWeek.SATURDAY
- SUNDAY: DayOfWeek¶
Representing Sunday, with a str value of
'Sunday', anindexof 6, and anisoIndexof 7.Access via:
DayOfWeek.SUNDAY
- THURSDAY: DayOfWeek¶
Representing Thursday, with a str value of
'Thursday', anindexof 3, and anisoIndexof 4.Access via:
DayOfWeek.THURSDAY
- TUESDAY: DayOfWeek¶
Representing Tuesday, with a str value of
'Tuesday', anindexof 1, and anisoIndexof 2.Access via:
DayOfWeek.TUESDAY
- WEDNESDAY: DayOfWeek¶
Representing Wednesday, with a str value of
'Wednesday', anindexof 2, and anisoIndexof 3.Access via:
DayOfWeek.WEDNESDAY
- class degreedays.time.DayRange(first: date, last: date)¶
Specifies a range of one or more days e.g. 2020-01-01 to 2020-12-31.
- Parameters:
first (datetime.date) – the first day that the
DayRangeshould include.last (datetime.date) – the last day that the
DayRangeshould include.
- Raises:
TypeError – if either first or last is not a
datetime.date.ValueError – if first is after last.
For example:
from datetime import date dayRange = DayRange(date(2020, 1, 1), date(2020, 12, 31))
- __iter__() Iterator[datetime.date]¶
To iterate over each
datetime.datewithin aDayRange. For example:for d in dayRange: print(d)
- __len__() int¶
To get the number of days covered by a
DayRange(always 1 or more). For example:numberOfDays = len(dayRange)
- contains(testDateOrDayRange: date | DayRange) bool¶
Returns True if the specified testDateOrDayRange is contained within this
DayRange; False otherwise.- Parameters:
testDateOrDayRange (datetime.date | DayRange) – a
datetime.dateorDayRangeto test for containment within thisDayRange.- Returns:
True if testDateOrDayRange is a
datetime.datethat is equal to or after thefirstday of thisDayRangeand equal to or before thelastday of thisDayRange, or if testDateOrDayRange is aDayRangewith afirstday equal to or after thefirstday of thisDayRangeand alastday equal to or before thelastday of thisDayRange; False otherwise.- Raises:
TypeError – if testDateOrDayRange is neither a
datetime.datenor aDayRange.
- class degreedays.time.DayRanges(*args: DayRange | Iterable[DayRange])¶
A chronologically-ordered set of one or more non-overlapping
DayRangeobjects.Create by passing in any number of
DayRangeobjects e.g.dayRanges = DayRanges(dayRange1, dayRange2, dayRange3)
or by passing in a sequence of
DayRangeobjects e.g.listOfDayRangeObjects = [dayRange1, dayRange2, dayRange3] dayRanges = DayRanges(listOfDayRangeObjects)
- Raises:
- __getitem__(index: int) DayRange¶
To get the
DayRangeobject at the specified index. For example:first = dayRanges[0]
- __iter__()¶
To iterate over the
DayRangeobjects in this set. For example:for r in dayRanges: print(r)
- class degreedays.time.StartOfMonth(dayOfMonth: int)¶
Specifies a definition of “months” that begin on a specified day of the month (e.g. 1 for calendar months).
- Parameters:
dayOfMonth (int) – a number between 1 and 28 (inclusive) indicating which day should be taken as the start of the “month”. Pass 1 to specify regular calendar months.
- Raises:
TypeError – if dayOfMonth is not an int.
ValueError – if dayOfMonth is less than 1 or greater than 28.
- class degreedays.time.StartOfYear(monthOfYear: int, dayOfMonth: int)¶
Specifies a definition of “years” that begin on a specified day of the year (e.g. January 1st for calendar years).
- Parameters:
monthOfYear (int) – a number between 1 and 12 (inclusive) indicating the month of the year in which the “year” should start. For example, if you’re working with UK financial years, choose 4 to specify that your “years” start in April.
dayOfMonth (int) – a number between 1 and the number of days in monthOfYear (inclusive) indicating which day in monthOfYear should be taken as the first day of the “year”. Note that the upper limit for February (
monthOfYear == 2) is 28, not 29, since February only has 29 days on leap years and aStartOfYearmust be applicable to all years.
- Raises:
TypeError – if monthOfYear or dayOfMonth is not an int.
ValueError – if monthOfYear and/or dayOfMonth are invalid according to the rules explained above.
- property dayOfMonth: int¶
The number between 1 and the number of days in
monthOfYear(inclusive) indicating which day inmonthOfYearis the first day of the “year” defined by thisStartOfYear.If
monthOfYearis 2 (for February), thisdayOfMonthwill never be greater than 28, as February 29th only exists in leap years, andStartOfYearhas to be applicable to all years.
- property monthOfYear: int¶
The number between 1 (January) and 12 (December) indicating the month of the calendar year in which the “year” defined by this
StartOfYearstarts.