1- # Period
1+ # Interval
22
3- When you subtract a ` DateTime ` instance from another, or use the ` diff() ` method, it will return a ` Period ` instance.
3+ When you subtract a ` DateTime ` instance from another, or use the ` diff() ` method, it will return an ` Interval ` instance.
44It inherits from the [ Duration] ( #duration ) class with the added benefit that it is aware of the
55instances that generated it, so that it can give access to more methods and properties:
66
@@ -10,29 +10,29 @@ instances that generated it, so that it can give access to more methods and prop
1010>> > start = pendulum.datetime(2000 , 11 , 20 )
1111>> > end = pendulum.datetime(2016 , 11 , 5 )
1212
13- >> > period = end - start
13+ >> > interval = end - start
1414
15- >> > period .years
15+ >> > interval .years
161615
17- >> > period .months
17+ >> > interval .months
181811
19- >> > period .in_years()
19+ >> > interval .in_years()
202015
21- >> > period .in_months()
21+ >> > interval .in_months()
2222191
2323
2424# Note that the weeks property
2525# will change compared to the Duration class
26- >> > period .weeks
26+ >> > interval .weeks
27272 # 832 for the duration
2828
2929# However the days property will still remain the same
3030# to keep the compatibility with the timedelta class
31- >> > period .days
31+ >> > interval .days
32325829
3333```
3434
35- Be aware that a period , just like an interval , is compatible with the ` timedelta ` class regarding
35+ Be aware that an interval , just like an duration , is compatible with the ` timedelta ` class regarding
3636its attributes. However, its custom attributes (like ` remaining_days ` ) will be aware of any DST
3737transitions that might have occurred and adjust accordingly. Let's take an example:
3838
@@ -42,42 +42,42 @@ transitions that might have occurred and adjust accordingly. Let's take an examp
4242>> > start = pendulum.datetime(2017 , 3 , 7 , tz = ' America/Toronto' )
4343>> > end = start.add(days = 6 )
4444
45- >> > period = end - start
45+ >> > interval = end - start
4646
4747# timedelta properties
48- >> > period .days
48+ >> > interval .days
49495
50- >> > period .seconds
50+ >> > interval .seconds
515182800
5252
53- # period properties
54- >> > period .remaining_days
53+ # interval properties
54+ >> > interval .remaining_days
55556
56- >> > period .hours
56+ >> > interval .hours
57570
58- >> > period .remaining_seconds
58+ >> > interval .remaining_seconds
59590
6060```
6161
6262!!!warning
6363
6464 Due to their nature (fixed duration between two datetimes), most arithmetic operations will
65- return a `Duration` instead of a `Period `.
65+ return a `Duration` instead of an `Interval `.
6666
6767 ```python
6868 >>> import pendulum
6969
7070 >>> dt1 = pendulum.datetime(2016, 8, 7, 12, 34, 56)
7171 >>> dt2 = dt1.add(days=6, seconds=34)
72- >>> period = pendulum.period (dt1, dt2)
73- >>> period * 2
72+ >>> interval = pendulum.interval (dt1, dt2)
73+ >>> interval * 2
7474 Duration(weeks=1, days=5, minutes=1, seconds=8)
7575 ```
7676
7777
7878## Instantiation
7979
80- You can create an instance by using the ` period ()` helper:
80+ You can create an instance by using the ` interval ()` helper:
8181
8282``` python
8383
@@ -86,39 +86,39 @@ You can create an instance by using the `period()` helper:
8686>> > start = pendulum.datetime(2000 , 1 , 1 )
8787>> > end = pendulum.datetime(2000 , 1 , 31 )
8888
89- >> > period = pendulum.period (start, end)
89+ >> > interval = pendulum.interval (start, end)
9090```
9191
92- You can also make an inverted period :
92+ You can also make an inverted interval :
9393
9494``` python
95- >> > period = pendulum.period (end, start)
96- >> > period .remaining_days
95+ >> > interval = pendulum.interval (end, start)
96+ >> > interval .remaining_days
9797- 2
9898```
9999
100- If you have inverted dates but want to make sure that the period is positive,
100+ If you have inverted dates but want to make sure that the interval is positive,
101101you should set the ` absolute ` keyword argument to ` True ` :
102102
103103``` python
104- >> > period = pendulum.period (end, start, absolute = True )
105- >> > period .remaining_days
104+ >> > interval = pendulum.interval (end, start, absolute = True )
105+ >> > interval .remaining_days
1061062
107107```
108108
109109## Range
110110
111- If you want to iterate over a period , you can use the ` range() ` method:
111+ If you want to iterate over a interval , you can use the ` range() ` method:
112112
113113``` python
114114>> > import pendulum
115115
116116>> > start = pendulum.datetime(2000 , 1 , 1 )
117117>> > end = pendulum.datetime(2000 , 1 , 10 )
118118
119- >> > period = pendulum.period (start, end)
119+ >> > interval = pendulum.interval (start, end)
120120
121- >> > for dt in period .range(' days' ):
121+ >> > for dt in interval .range(' days' ):
122122>> > print (dt)
123123
124124' 2000-01-01T00:00:00+00:00'
@@ -141,7 +141,7 @@ If you want to iterate over a period, you can use the `range()` method:
141141You can pass an amount for the passed unit to control the length of the gap:
142142
143143``` python
144- >> > for dt in period .range(' days' , 2 ):
144+ >> > for dt in interval .range(' days' , 2 ):
145145>> > print (dt)
146146
147147' 2000-01-01T00:00:00+00:00'
@@ -151,18 +151,18 @@ You can pass an amount for the passed unit to control the length of the gap:
151151' 2000-01-09T00:00:00+00:00'
152152```
153153
154- You can also directly iterate over the ` Period ` instance,
154+ You can also directly iterate over the ` Interval ` instance,
155155the unit will be ` days ` in this case:
156156
157157``` python
158- >> > for dt in period :
158+ >> > for dt in interval :
159159>> > print (dt)
160160```
161161
162- You can check if a ` DateTime ` instance is inside a period using the ` in ` keyword:
162+ You can check if a ` DateTime ` instance is inside a interval using the ` in ` keyword:
163163
164164``` python
165165>> > dt = pendulum.datetime(2000 , 1 , 4 )
166- >> > dt in period
166+ >> > dt in interval
167167True
168168```
0 commit comments