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'
, anindex
of 4, and anisoIndex
of 5.Access via:
DayOfWeek.FRIDAY
- MONDAY: DayOfWeek¶
Representing Monday, with a str value of
'Monday'
, anindex
of 0, and anisoIndex
of 1.Access via:
DayOfWeek.MONDAY
- SATURDAY: DayOfWeek¶
Representing Saturday, with a str value of
'Saturday'
, anindex
of 5, and anisoIndex
of 6.Access via:
DayOfWeek.SATURDAY
- SUNDAY: DayOfWeek¶
Representing Sunday, with a str value of
'Sunday'
, anindex
of 6, and anisoIndex
of 7.Access via:
DayOfWeek.SUNDAY
- THURSDAY: DayOfWeek¶
Representing Thursday, with a str value of
'Thursday'
, anindex
of 3, and anisoIndex
of 4.Access via:
DayOfWeek.THURSDAY
- TUESDAY: DayOfWeek¶
Representing Tuesday, with a str value of
'Tuesday'
, anindex
of 1, and anisoIndex
of 2.Access via:
DayOfWeek.TUESDAY
- WEDNESDAY: DayOfWeek¶
Representing Wednesday, with a str value of
'Wednesday'
, anindex
of 2, and anisoIndex
of 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
DayRange
should include.last (datetime.date) – the last day that the
DayRange
should 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.date
within 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.date
orDayRange
to test for containment within thisDayRange
.- Returns:
True if testDateOrDayRange is a
datetime.date
that is equal to or after thefirst
day of thisDayRange
and equal to or before thelast
day of thisDayRange
, or if testDateOrDayRange is aDayRange
with afirst
day equal to or after thefirst
day of thisDayRange
and alast
day equal to or before thelast
day of thisDayRange
; False otherwise.- Raises:
TypeError – if testDateOrDayRange is neither a
datetime.date
nor aDayRange
.
- class degreedays.time.DayRanges(*args: DayRange | Iterable[DayRange])¶
A chronologically-ordered set of one or more non-overlapping
DayRange
objects.Create by passing in any number of
DayRange
objects e.g.dayRanges = DayRanges(dayRange1, dayRange2, dayRange3)
or by passing in a sequence of
DayRange
objects e.g.listOfDayRangeObjects = [dayRange1, dayRange2, dayRange3] dayRanges = DayRanges(listOfDayRangeObjects)
- Raises:
- __getitem__(index: int) DayRange ¶
To get the
DayRange
object at the specified index. For example:first = dayRanges[0]
- __iter__()¶
To iterate over the
DayRange
objects 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 aStartOfYear
must 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 inmonthOfYear
is the first day of the “year” defined by thisStartOfYear
.If
monthOfYear
is 2 (for February), thisdayOfMonth
will never be greater than 28, as February 29th only exists in leap years, andStartOfYear
has 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
StartOfYear
starts.