BaseIsoWeek
class¶
iso_week_date.base.BaseIsoWeek
¶
Bases: ABC
, ComparatorMixin
, ConverterMixin
, ParserMixin
Base abstract class for IsoWeek
and IsoWeekDate
classes.
It defines the common interface for both classes and implements the common methods between them.
Attributes:
Name | Type | Description |
---|---|---|
value_ |
str
|
stores the string value representing the iso-week date in the |
offset_ |
timedelta
|
class variable, stores the offset to be used when converting to and from |
_pattern |
Pattern
|
class variable, stores the regex pattern to validate iso-week string format. Semiprivate, do not use it directly. |
_format |
str
|
class variable, stores the string format of the iso-week date. Semiprivate, do not use it directly. |
_date_format |
str
|
class variable, stores the string format with datetime conventions. Semiprivate, do not use it directly. |
Source code in iso_week_date/base.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
name: str
property
¶
Returns class name.
quarter: int
property
¶
Returns quarter number as integer.
The first three quarters have 13 weeks, while the last one has either 13 or 14 weeks depending on the year:
- Q1: weeks from 1 to 13
- Q2: weeks from 14 to 26
- Q3: weeks from 27 to 39
- Q4: weeks from 40 to 52 (or 53 if applicable)
Examples:
week: int
property
¶
year: int
property
¶
__add__(other)
abstractmethod
¶
Implementation of addition operator.
__init__(value)
¶
Initializes BaseIsoWeek
object from iso-week string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
ISO Week string to initialize |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in iso_week_date/base.py
__next__()
¶
__repr__()
¶
__str__()
¶
__sub__(other)
abstractmethod
¶
Implementation of subtraction operator.
Source code in iso_week_date/base.py
range(start, end, *, step=1, inclusive='both', as_str=True)
classmethod
¶
Generates BaseIsoWeek
(or str
) between start
and end
values with given step
.
inclusive
parameter can be used to control inclusion of start
and/or end
week values.
If as_str
is flagged as True
, it will return str values, otherwise it will return BaseIsoWeek
objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
BaseIsoWeek_T
|
Starting value. It can be |
required |
end |
BaseIsoWeek_T
|
Ending value. It can be |
required |
step |
int
|
Step between generated values, must be positive integer. |
1
|
inclusive |
Literal['both', 'left', 'right', 'neither']
|
Inclusive type, can be one of "both", "left", "right" or "neither". |
'both'
|
as_str |
bool
|
Whether to return |
True
|
Returns:
Type | Description |
---|---|
None
|
Generator of |
Raises:
Type | Description |
---|---|
ValueError
|
If any of the following conditions is met:
|
TypeError
|
If |
Examples:
from iso_week_date import IsoWeek
tuple(
IsoWeek.range(
start="2023-W01",
end="2023-W07",
step=2,
inclusive="both",
as_str=True,
)
)
# ('2023-W01', '2023-W03', '2023-W05', '2023-W07')
Source code in iso_week_date/base.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|