@@ -61,29 +61,17 @@ besides behaving as expected, all accept a timezone parameter and each has their
6161 print (yesterday)
6262 ' 2016-06-27T00:00:00-05:00'
6363
64- The next group of static helpers are the ``from_xxx() `` and ``create() `` helpers.
65- Most of the static ``create `` functions allow you to provide
64+ The next helper is ``create() `` which allows you to provide
6665as many or as few arguments as you want and will provide default values for all others.
67- Generally default values are the current date, time set to ``00:00:00 `` and ``UTC `` timezone.
6866
6967.. code-block :: python
7068
71- pendulum.from_date(year, month, day, tz)
72- pendulum.from_time(hour, minute, second, microsecond, tz)
7369 pendulum.create(year, month, day, hour, minute, second, microsecond, tz)
7470
75- ``from_date() `` will default the time to ``00:00:00 ``. ``from_time() `` will default the date to today.
7671 ``create() `` will default any null parameter to the current date for the date part and to ``00:00:00 `` for time.
77- As before, the ``tz `` defaults to the ``UTC `` timezone and otherwise can be a ``TimezoneInfo `` instance
72+ As before, the ``tz `` defaults to the ``UTC `` timezone and otherwise can be a ``Timezone `` instance
7873or simply a string timezone value.
7974
80- .. code-block :: python
81-
82- xmas_this_year = pendulum.from_date(None , 12 , 25 )
83- # Year defaults to current year
84- y2k = pendulum.create(2000 , 1 , 1 , 0 , 0 , 0 )
85- noon_london_tz = pendulum.from_time(12 , 0 , 0 , tz = ' Europe/London' )
86-
8775.. code-block :: python
8876
8977 pendulum.from_format(time, format , tz)
@@ -138,3 +126,118 @@ you can create a ``Pendulum`` instance via the ``instance()`` function.
138126 p = pendulum.instance(dt)
139127 print (p.to_datetime_string())
140128 ' 2008-01-01 00:00:00'
129+
130+ Parsing
131+ -------
132+
133+ You can also instantiate ``Pendulum `` instances by passing a string to the ``parse() `` method.
134+
135+ .. code-block :: python
136+
137+ import pendulum
138+
139+ dt = pendulum.parse(' 1975-05-21 22:00:00' )
140+ print (dt)
141+ ' 1975-05-21T22:00:00+00:00
142+
143+ The library natively supports the RFC 3339 format, most ISO 8601 formats and some other common formats. If you pass a non-standard or more complicated
144+ string, the library will fallback on the `dateutil <https://dateutil.readthedocs.io >`_ parser.
145+
146+ RFC 3339
147+ ~~~~~~~~
148+
149+ +-----------------------------------+-------------------------------------------+
150+ | String |Output |
151+ +===================================+===========================================+
152+ | 1996-12-19T16:39:57-08:00 |1996-12-19T16:39:57-08:00 |
153+ +-----------------------------------+-------------------------------------------+
154+ | 1990-12-31T23:59:59Z |1990-12-31T23:59:59+00:00 |
155+ +-----------------------------------+-------------------------------------------+
156+
157+ ISO 8601
158+ ~~~~~~~~
159+
160+ Datetime
161+ ++++++++
162+
163+ +-----------------------------------+-------------------------------------------+
164+ | String |Output |
165+ +===================================+===========================================+
166+ | 20161001T143028+0530 |2016-10-01T14:30:28+05:30 |
167+ +-----------------------------------+-------------------------------------------+
168+ | 20161001T14 |2016-10-01T14:00:00+00:00 |
169+ +-----------------------------------+-------------------------------------------+
170+
171+ Date
172+ ++++
173+
174+ +-----------------------------------+-------------------------------------------+
175+ | String |Output |
176+ +===================================+===========================================+
177+ | 2012 |2012-01-01T00:00:00+00:00 |
178+ +-----------------------------------+-------------------------------------------+
179+ | 2012-05-03 |2012-05-03T00:00:00+00:00 |
180+ +-----------------------------------+-------------------------------------------+
181+ | 20120503 |2012-05-03T00:00:00+00:00 |
182+ +-----------------------------------+-------------------------------------------+
183+ | 2012-05 |2016-10-01T14:00:00+00:00 |
184+ +-----------------------------------+-------------------------------------------+
185+
186+ Ordinal day
187+ +++++++++++
188+
189+ +-----------------------------------+-------------------------------------------+
190+ | String |Output |
191+ +===================================+===========================================+
192+ | 2012-007 |2012-01-07T00:00:00+00:00 |
193+ +-----------------------------------+-------------------------------------------+
194+ | 2012007 |2012-01-07T00:00:00+00:00 |
195+ +-----------------------------------+-------------------------------------------+
196+
197+ Week number
198+ +++++++++++
199+
200+ +-----------------------------------+-------------------------------------------+
201+ | String |Output |
202+ +===================================+===========================================+
203+ | 2012-W05 |2012-01-30T00:00:00+00:00 |
204+ +-----------------------------------+-------------------------------------------+
205+ | 2012W05 |2012-01-30T00:00:00+00:00 |
206+ +-----------------------------------+-------------------------------------------+
207+ | 2012-W05-5 |2012-02-03T00:00:00+00:00 |
208+ +-----------------------------------+-------------------------------------------+
209+ | 2012W055 |2012-02-03T00:00:00+00:00 |
210+ +-----------------------------------+-------------------------------------------+
211+
212+ Time
213+ ++++
214+
215+ When passing only time information the date will default to today.
216+
217+ +-----------------------------------+-------------------------------------------+
218+ | String |Output |
219+ +===================================+===========================================+
220+ | 00:00 |2016-12-17T00:00:00+00:00 |
221+ +-----------------------------------+-------------------------------------------+
222+ | 12:04:23 |2016-12-17T12:04:23+00:00 |
223+ +-----------------------------------+-------------------------------------------+
224+ | 120423 |2016-12-17T12:04:23+00:00 |
225+ +-----------------------------------+-------------------------------------------+
226+ | 12:04:23.45 |2016-12-17T12:04:23.450000+00:00 |
227+ +-----------------------------------+-------------------------------------------+
228+
229+
230+ .. note ::
231+
232+ You can pass the ``strict `` keyword argument to ``parse() `` to get the exact type
233+ that the string represents:
234+
235+ .. code-block :: python
236+
237+ import pendulum
238+
239+ pendulum.parse(' 2012-05-03' , strict = True )
240+ # <Date [2012-05-03]>
241+
242+ pendulum.parse(' 12:04:23' , strict = True )
243+ # <Time [12:04:23]>
0 commit comments