1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# flake8: noqa
"""PyCFCalendar represents a calendar object."""
"""Create a PyCFCalendar from a string representation.
Args:
s (str): The string representation of the calendar.
Returns:
PyCFCalendar: A PyCFCalendar object.
Raises:
ValueError: If the calendar string cannot be parsed.
"""
...
"""PyCFDuration is a wrapper around Rust CFDuration.
All the methods depend on the Calendar definitions found in
[udunits package](https://github.com/nco/nco/blob/master/data/udunits.dat).
This duration can be added to a PyCFDatetime.
The result of the subtraction between two PyCFDatetime objects gives a PyCFDuration.
"""
"""
Makes a new PyCFDuration with the given number of years and specific calendar.
Args:
years (int): Number of years.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of month and specific calendar.
Args:
month (int): Number of month.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of weeks and specific calendar.
Args:
weeks (int): Number of weeks.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of days and specific calendar.
Args:
days (int): Number of days.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of hours and specific calendar.
Args:
hours (int): Number of hours.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of minutes and specific calendar.
Args:
minutes (int): Number of minutes.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of seconds and specific calendar.
Args:
seconds (int): Number of seconds.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of milliseconds and specific calendar.
Args:
milliseconds (int): Number of milliseconds.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of microseconds and specific calendar.
Args:
microseconds (int): Number of microseconds.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Makes a new PyCFDuration with the given number of nanoseconds and specific calendar.
Args:
nanoseconds (int): Number of nanoseconds.
calendar (PyCFCalendar): The calendar for the duration.
Returns:
PyCFDuration: A new PyCFDuration object.
"""
...
"""
Returns the total number of years in the duration.
Returns:
float: Number of years.
"""
...
"""
Returns the total number of months in the duration.
Returns:
float: Number of months.
"""
...
"""
Returns the total number of weeks in the duration.
Returns:
float: Number of weeks.
"""
...
"""
Returns the total number of days in the duration.
Returns:
float: Number of days.
"""
...
"""
Returns the total number of hours in the duration.
Returns:
float: Number of hours.
"""
...
"""
Returns the total number of minutes in the duration.
Returns:
float: Number of minutes.
"""
...
"""
Returns the total number of seconds in the duration.
Returns:
float: Number of seconds.
"""
...
"""
Returns the total number of milliseconds in the duration.
Returns:
float: Number of milliseconds.
"""
...
"""
Returns the total number of microseconds in the duration.
Returns:
float: Number of microseconds.
"""
...
"""
Returns the total number of nanoseconds in the duration.
Returns:
float: Number of nanoseconds.
"""
...
"""
PyCFDatetime is a wrapper around Rust CFDatetime.
It represents a date in a specific calendar.
All the methods depend on the Calendar definitions found in
[udunits package](https://github.com/nco/nco/blob/master/data/udunits.dat).
"""
"""
Makes a new PyCFDatetime with given year, month, day, hour, minute, second, and specific calendar.
Args:
year (int): The year.
month (int): The month.
day (int): The day.
hour (int): The hour.
minute (int): The minute.
second (float): The second.
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
"""
...
"""
Returns the year, month, and day of the date.
Returns:
Tuple[int, int, int]: A tuple of (year, month, day).
"""
...
"""
Returns the hour, minute, and second of the time.
Returns:
Tuple[int, int, int]: A tuple of (hour, minute, second).
"""
...
"""
Returns the year, month, day, hour, minute, and second of the datetime.
Returns:
Tuple[int, int, int, int, int, int]: A tuple of (year, month, day, hour, minute, second).
"""
...
"""
Makes a new PyCFDatetime with given year, month, day, hour, minute, second, and specific calendar.
Args:
year (int): The year.
month (int): The month.
day (int): The day.
hour (int): The hour.
minute (int): The minute.
second (float): The second.
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
"""
...
"""
Makes a new PyCFDatetime with given hour, minute, second, and specific calendar.
The year, month, and day are set to 1970-01-01.
Args:
hour (int): The hour.
minute (int): The minute.
second (float): The second.
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
"""
...
"""
Makes a new PyCFDatetime with given year, month, day, and specific calendar.
The hour, minute, and second are set to 0.
Args:
year (int): The year.
month (int): The month.
day (int): The day.
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
"""
...
"""
Makes a new PyCFDatetime with given timestamp, nanoseconds, and specific calendar.
Args:
timestamp (int): The timestamp.
nanoseconds (int): The nanoseconds.
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
"""
...
"""Change the calendar of the PyCFDatetime.
This can be considered as safe as this method try to recreate the datetime with the same year, month,
day, hour, minute, second and nanoseconds.
Args:
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
Raises:
ValueError: If the date is not possible in the target calendar.
"""
...
"""Change the calendar of the CFDatetime using the timestamp
Be aware that there is highly chance that the two dates do not correspond.
However their distances from epoch are the same.
Args:
calendar (PyCFCalendar): The calendar for the datetime.
Returns:
PyCFDatetime: A new PyCFDatetime object.
Raises:
ValueError: If the date is not possible in the target calendar.
"""
...
"""
Converts the object to a Python datetime object using year, month, day, hour, minute,
and second
Returns:
A datetime object representing the same date and time as the object.
Raises:
ValueError: If the date cannot be converted to a datetime
"""
...
"""
Converts the object to a Python datetime object using the timestamp
Returns:
A datetime object representing the same underlying timestamp
Raises:
ValueError: If the date cannot be converted to a datetime
"""
...
"""Convert a list of numbers to PyCFDatetime objects based on the specified calendar.
Args:
arr : Iterable[Union[int, float]]
Array of numbers to convert to PyCFDatetime
units : str
Valid CF units
calendar : str
CF calendar name. Should be one of "standard", "gregorian",
"proleptic_gregorian", "julian", "all_leap", "no_leap", "360_day", "365_day", "366_day".
If the calendar is not recognized, "standard" will be used
Raises:
ValueError
If the date is not valid in the calendar
Returns:
List[PyCFDatetime]
List of PyCFDatetime objects
"""
...
"""Convert a list of numbers to datetime objects based on the specified calendar.
Args:
arr : Iterable[Union[int, float]]
Array of numbers to convert to datetime
units : str
Valid CF units
calendar : str
CF calendar name. Should be one of "standard", "gregorian",
"proleptic_gregorian", "julian", "all_leap", "no_leap", "360_day", "365_day", "366_day".
If the calendar is not recognized, "standard" will be used
from_timestamp : bool
If True, the date will be converted using timestamp value from epoch and python datetime
`.from_timestamp` method will be used. This method guarantee that the date is valid if no
overflow occurs. While the distance from epoch is the same, the date are likely to be different.
If False, the date will be converted using python datetime constructor method : the year, month, day, hour, minute, second and nanoseconds will be extyracted from PyCFDatetime object and given back to python datetime constructor. There is no guarantee that the date is valid in the calendar. This method is also considerably slower than using the timestamp.
Default value is False.
Raises:
ValueError
If the date is not valid in the calendar
Returns:
List[datetime.datetime]
List of datetime.datetime objects
"""
...
"""Convert a list of PyCFDatetime objects to a list of numbers based on calendar, units, and dtype.
Args:
datetimes : List[PyCFDatetime]
List of PyCFDatetime objects
units : str
Valid CF units
calendar : str
CF calendar name. Should be one of "standard", "gregorian",
dtype : str
32 bit integer : "i32"
64 bit integer : "i64", "i", "integer", "int"
32 bit float : "f32"
64 bit float : "f64", "f", "float"
Raises:
ValueError
If the date is not valid in the calendar
ValueError
If the dtype is not recognized
Returns:
Union[int, float]
List of numbers based on calendar, units, and dtype
"""
...
"""Convert a list of python datetime to a list of numbers based on calendar, units, and dtype.
Since the backend is implemented in Rust, we need to call python datetimes arguments
in order to convert them to rust object. This inevitably leads to a lot of overhead and
lower performance thant using num2date.
Args:
datetimes : List[datetime.datetime]
List of python datetime.datetime objects
units : str
Valid CF units
calendar : str
CF calendar name. Should be one of "standard", "gregorian",
dtype : str
32 bit integer : "i32"
64 bit integer : "i64", "i", "integer", "int"
32 bit float : "f32"
64 bit float : "f64", "f", "float"
Raises:
ValueError
If the date is not valid in the calendar
ValueError
If the dtype is not recognized
Returns:
Union[int, float]
List of numbers based on calendar, units, and dtype
"""
...