@@ -25,10 +25,7 @@ Pendulum is a Python package to ease datetimes manipulation.
2525It is heavily inspired by `Carbon <http://carbon.nesbot.com >`_ for PHP.
2626
2727The ``Pendulum `` class is a drop-in replacement for the native ``datetime ``
28- class (it is inherited from it) with the exception that its mutable.
29-
30- Unlike the native class, most of the methods modify the current instance
31- of ``Pendulum `` in place. If you want to modify a copy just use the ``copy() `` method.
28+ class (it is inherited from it).
3229
3330Special care has been taken to ensure timezones are handled correctly,
3431and where appropriate are based on the underlying ``tzinfo `` implementation.
@@ -39,9 +36,10 @@ For example all comparisons are done in UTC or in the timezone of the datetime b
3936 dt_toronto = Pendulum.create_from_date(2012 , 1 , 1 , ' America/Toronto' )
4037 dt_vancouver = Pendulum.create_from_date(2012 , 1 , 1 , ' America/Vancouver' )
4138
42- print (dt_vancouver.diff_in_hours(dt_toronto)) # 3
39+ print (dt_vancouver.diff_in_hours(dt_toronto))
40+ 3
4341
44- The default timezone, except when using the ``now() `` method will always be ``UTC ``.
42+ The default timezone, except when using the ``now() ``, method will always be ``UTC ``.
4543
4644.. note ::
4745
@@ -79,20 +77,16 @@ Instantiation
7977=============
8078
8179There are several different methods available to create a new instance of Pendulum.
82- First there is a constructor. It overrides the parent constructor to be more flexible.
83- Basically, unlike ``datetime `` you can omit parameters and any omitted parameter will
84- default to its ``now() `` value. However, if you provide the ``year ``, ``month ``, ``day ``
85- it will emulate the default ``datetime `` behavior.
80+ First there is a constructor. It accepts the same parameters as the standard class.
8681
8782.. code-block :: python
8883
8984 from pendulum import Pendulum
9085
91- dt = Pendulum() # equivalent to Pendulum.utcnow( )
86+ dt = Pendulum(2015 , 2 , 5 , tzinfo = ' America/Vancouver ' )
9287 isinstance (dt, datetime)
9388 True
9489
95- dt = Pendulum(2015 , 2 , 5 , tzinfo = ' America/Vancouver' )
9690 dt = Pendulum.now(- 5 )
9791
9892 You'll notice above that the timezone (2nd) parameter was passed as a string and an integer
@@ -103,18 +97,20 @@ This is again shown in the next example which also introduces the ``now()`` func
10397
10498.. code-block :: python
10599
106- now = Pendulum.now()
100+ import pendulum
107101
108- now_in_london_tz = Pendulum.now(pytz.timezone(' Europe/London' ))
102+ now = pendulum.now()
103+
104+ now_in_london_tz = pendulum.now(pytz.timezone(' Europe/London' ))
109105
110106 # or just pass the timezone as a string
111- now_in_london_tz = Pendulum .now(' Europe/London' )
107+ now_in_london_tz = pendulum .now(' Europe/London' )
112108 print (now_in_london_tz.timezone_name)
113109 ' Europe/London'
114110
115111 # or to create a date with a timezone of +1 to GMT
116112 # during DST then just pass an integer
117- print (Pendulum .now(1 ).timezone_name))
113+ print (pendulum .now(1 ).timezone_name))
118114 None
119115
120116 .. note ::
@@ -128,19 +124,19 @@ besides behaving as expected, all accept a timezone parameter and each has their
128124
129125.. code-block :: python
130126
131- now = Pendulum .now()
127+ now = pendulum .now()
132128 print (now)
133129 ' 2016-06-28T16:51:45.978473-05:00'
134130
135- today = Pendulum .today()
131+ today = pendulum .today()
136132 print (today)
137133 ' 2016-06-28T00:00:00-05:00'
138134
139- tomorrow = Pendulum .tomorrow(' Europe/London' )
135+ tomorrow = pendulum .tomorrow(' Europe/London' )
140136 print (tomorrow)
141137 ' 2016-06-29T00:00:00+01:00'
142138
143- yesterday = Pendulum .yesterday()
139+ yesterday = pendulum .yesterday()
144140 print (yesterday)
145141 ' 2016-06-27T00:00:00-05:00'
146142
@@ -151,9 +147,9 @@ Generally default values are the current date, time or timezone.
151147
152148.. code-block :: python
153149
154- Pendulum.create_from_date (year, month, day, tz)
155- Pendulum.create_from_time (hour, minute, second, microsecond, tz)
156- Pendulum .create(year, month, day, hour, minute, second, microsecond, tz)
150+ pendulum.from_date (year, month, day, tz)
151+ pendulum.from_time (hour, minute, second, microsecond, tz)
152+ pendulum .create(year, month, day, hour, minute, second, microsecond, tz)
157153
158154 ``create_from_date() `` will default the time to now. ``create_from_time() `` will default the date to today.
159155``create() `` will default any null parameter to the current respective value.
@@ -163,58 +159,62 @@ is specified but no minutes or seconds, they will get defaulted to ``0``.
163159
164160.. code-block :: python
165161
166- xmas_this_year = Pendulum.create_from_date (None , 12 , 25 ) # Year defaults to current year
167- y2k = Pendulum .create(2000 , 1 , 1 , 0 , 0 , 0 )
168- noon_london_tz = Pendulum.create_from_time (12 , 0 , 0 , tz = ' Europe/London' )
162+ xmas_this_year = pendulum._from_date (None , 12 , 25 ) # Year defaults to current year
163+ y2k = pendulum .create(2000 , 1 , 1 , 0 , 0 , 0 )
164+ noon_london_tz = pendulum.from_time (12 , 0 , 0 , tz = ' Europe/London' )
169165
170166 .. code-block :: python
171167
172- Pendulum.create_from_format (time, format , tz)
168+ pendulum.from_format (time, format , tz)
173169
174170 ``create_from_format() `` is mostly a wrapper for the base Python function ``datetime.strptime() ``.
175171The difference being the addition the ``tz `` argument that can be a ``tzinfo `` instance or a string timezone value
176172(defaults to ``UTC ``).
177173
178174.. code-block :: python
179175
180- Pendulum.create_from_format (' 1975-05-21 22' , ' %Y-%m-%d %H' ).to_datetime_string()
176+ pendulum.from_format (' 1975-05-21 22' , ' %Y-%m-%d %H' ).to_datetime_string()
181177 ' 1975-05-21 22:00:00'
182- Pendulum.create_from_format (' 1975-05-21 22' , ' %Y-%m-%d %H' , ' Europe/London' ).isoformat()
178+ pendulum.from_format (' 1975-05-21 22' , ' %Y-%m-%d %H' , ' Europe/London' ).isoformat()
183179 ' 1975-05-21T22:00:00+01:00'
184180
185181 # Using strptime is also possible (the timezone will be UTC)
186- Pendulum .strptime(' 1975-05-21 22' , ' %Y-%m-%d %H' ).isoformat()
182+ pendulum .strptime(' 1975-05-21 22' , ' %Y-%m-%d %H' ).isoformat()
187183
188184 The final ``create `` function is for working with unix timestamps.
189185``create_from_timestamp() `` will create a Pendulum instance equal to the given timestamp
190186and will set the timezone as well or default it to ``UTC ``.
191187
192188.. code-block :: python
193189
194- Pendulum.create_from_timestamp (- 1 ).to_datetime_string()
190+ pendulum.from_timestamp (- 1 ).to_datetime_string()
195191 ' 1969-12-31 23:59:59'
196192
197- Pendulum.create_from_timestamp (- 1 , ' Europe/London' ).to_datetime_string()
193+ pendulum.from_timestamp (- 1 , ' Europe/London' ).to_datetime_string()
198194 ' 1970-01-01 00:59:59'
199195
196+ # Using the standard fromtimestamp is also possible
197+ pendulum.fromtimestamp(- 1 ).to_datetime_string()
198+ ' 1969-12-31 23:59:59'
199+
200200 You can also create a ``copy() `` of an existing Pendulum instance.
201201As expected the date, time and timezone values are all copied to the new instance.
202202
203203.. code-block :: python
204204
205- dt = Pendulum .now()
206- print (dt.diff_in_years (dt.copy().add_year()))
205+ dt = pendulum .now()
206+ print (dt.diff (dt.copy().add_year()).in_years( ))
207207 1
208208
209- # dt was unchanged and still holds the value of Pendulum .now()
209+ # dt was unchanged and still holds the value of pendulum .now()
210210
211211 Finally, if you find yourself inheriting a ``datetime `` instance,
212- you can create a Pendulum instance via the ``instance() `` function.
212+ you can create a `` Pendulum `` instance via the ``instance() `` function.
213213
214214.. code-block :: python
215215
216216 dt = datetime(2008 , 1 , 1 )
217- p = Pendulum .instance(dt)
217+ p = pendulum .instance(dt)
218218 print (p.to_datetime_string())
219219 ' 2008-01-01 00:00:00'
220220
0 commit comments