Skip to content

Commit 8cb5c9b

Browse files
committed
Datetime
1 parent 5075e9a commit 8cb5c9b

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,27 +561,28 @@ from dateutil.tz import UTC, tzlocal, gettz
561561
```python
562562
<D/DTn> = D/DT.today() # Current local date or naive datetime.
563563
<DTn> = DT.utcnow() # Naive datetime from current UTC time.
564-
<DTa> = DT.now(<tz>) # Aware datetime from current tz time.
564+
<DTa> = DT.now(<tzinfo>) # Aware datetime from current tz time.
565565
```
566+
* **To extract time use `'<DTn>.time()'` or `'<DTa>.timetz()'`.**
566567

567568
### Timezone
568569
```python
569-
<tz> = UTC # UTC timezone. London without DST.
570-
<tz> = tzlocal() # Local timezone.
571-
<tz> = gettz('<Cont.>/<City>') # Timezone from 'Continent/City_Name' str.
570+
<tzinfo> = UTC # UTC timezone. London without DST.
571+
<tzinfo> = tzlocal() # Local timezone.
572+
<tzinfo> = gettz('<Cont.>/<City>') # Timezone from 'Continent/City_Name' str.
572573
```
573574

574575
```python
575-
<DTa> = <DT>.astimezone(<tz>) # Datetime, converted to passed timezone.
576-
<Ta/DTa> = <T/DT>.replace(tzinfo=<tz>) # Unconverted object with new timezone.
576+
<DTa> = <DT>.astimezone(<tzinfo>) # Datetime, converted to passed timezone.
577+
<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) # Unconverted object with new timezone.
577578
```
578579

579580
### Encode
580581
```python
581582
<D/T/DT> = D/T/DT.fromisoformat('<iso>') # Object from ISO string.
582583
<DT> = DT.strptime(<str>, '<format>') # Datetime from str, according to format.
583584
<D/DTn> = D/DT.fromordinal(<int>) # D/DTn from days since Christ.
584-
<DTa> = DT.fromtimestamp(<real>, <tz>) # DTa from seconds since Epoch in tz time.
585+
<DTa> = DT.fromtimestamp(<real>, <tz.>) # DTa from seconds since Epoch in tz time.
585586
```
586587
* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±<offset>]'`, or both separated by `'T'`. Offset is formatted as: `'HH:MM'`.**
587588
* **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...**
@@ -601,10 +602,15 @@ from dateutil.tz import UTC, tzlocal, gettz
601602
>>> dt.strftime("%A, %dth of %B '%y, %I:%M%p %Z")
602603
"Thursday, 14th of May '15, 11:39PM UTC+02:00"
603604
```
605+
* **For abbreviated weekday and month use `'%a'` and `'%b'`.**
604606

605-
#### Rest of the codes:
606-
* **`'a'` - Weekday, abbreviated name.**
607-
* **`'b'` - Month, abbreviated name.**
607+
### Arithmetics
608+
```python
609+
<D/DT> = <D/DT> ± <TD>
610+
<TD> = <TD> ± <TD>
611+
<TD> = <TD> */ <real>
612+
<float> = <TD> / <TD>
613+
```
608614

609615

610616
Arguments
@@ -1350,7 +1356,7 @@ cwd = Path()
13501356
```
13511357

13521358
```python
1353-
<iter> = <Path>.iterdir() # Iterator with filenames located at path.
1359+
<iter> = <Path>.iterdir() # Iterator of filenames located at path.
13541360
<iter> = <Path>.glob('<pattern>') # Filenames matching the wildcard pattern.
13551361
```
13561362

index.html

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,24 @@ <h3 id="constructors">Constructors</h3>
599599
<h3 id="now">Now</h3>
600600
<pre><code class="python language-python hljs">&lt;D/DTn&gt; = D/DT.today() <span class="hljs-comment"># Current local date or naive datetime.</span>
601601
&lt;DTn&gt; = DT.utcnow() <span class="hljs-comment"># Naive datetime from current UTC time.</span>
602-
&lt;DTa&gt; = DT.now(&lt;tz&gt;) <span class="hljs-comment"># Aware datetime from current tz time.</span>
602+
&lt;DTa&gt; = DT.now(&lt;tzinfo&gt;) <span class="hljs-comment"># Aware datetime from current tz time.</span>
603603
</code></pre>
604+
<ul>
605+
<li><strong>To extract time use <code class="python hljs"><span class="hljs-string">'&lt;DTn&gt;.time()'</span></code> or <code class="python hljs"><span class="hljs-string">'&lt;DTa&gt;.timetz()'</span></code>.</strong></li>
606+
</ul>
604607
<h3 id="timezone">Timezone</h3>
605-
<pre><code class="python language-python hljs">&lt;tz&gt; = UTC <span class="hljs-comment"># UTC timezone. London without DST.</span>
606-
&lt;tz&gt; = tzlocal() <span class="hljs-comment"># Local timezone.</span>
607-
&lt;tz&gt; = gettz(<span class="hljs-string">'&lt;Cont.&gt;/&lt;City&gt;'</span>) <span class="hljs-comment"># Timezone from 'Continent/City_Name' str.</span>
608+
<pre><code class="python language-python hljs">&lt;tzinfo&gt; = UTC <span class="hljs-comment"># UTC timezone. London without DST.</span>
609+
&lt;tzinfo&gt; = tzlocal() <span class="hljs-comment"># Local timezone.</span>
610+
&lt;tzinfo&gt; = gettz(<span class="hljs-string">'&lt;Cont.&gt;/&lt;City&gt;'</span>) <span class="hljs-comment"># Timezone from 'Continent/City_Name' str.</span>
608611
</code></pre>
609-
<pre><code class="python language-python apache hljs">&lt;DTa&gt; = &lt;DT&gt;.astimezone(&lt;tz&gt;) <span class="hljs-comment"># Datetime, converted to passed timezone.</span>
610-
&lt;Ta/DTa&gt; = &lt;T/DT&gt;.replace(tzinfo=&lt;tz&gt;) <span class="hljs-comment"># Unconverted object with new timezone.</span>
612+
<pre><code class="python language-python apache hljs">&lt;DTa&gt; = &lt;DT&gt;.astimezone(&lt;tzinfo&gt;) <span class="hljs-comment"># Datetime, converted to passed timezone.</span>
613+
&lt;Ta/DTa&gt; = &lt;T/DT&gt;.replace(tzinfo=&lt;tzinfo&gt;) <span class="hljs-comment"># Unconverted object with new timezone.</span>
611614
</code></pre>
612615
<h3 id="encode">Encode</h3>
613616
<pre><code class="python language-python apache hljs">&lt;D/T/DT&gt; = D/T/DT.fromisoformat(<span class="hljs-string">'&lt;iso&gt;'</span>) <span class="hljs-comment"># Object from ISO string.</span>
614617
&lt;DT&gt; = DT.strptime(&lt;str&gt;, <span class="hljs-string">'&lt;format&gt;'</span>) <span class="hljs-comment"># Datetime from str, according to format.</span>
615618
&lt;D/DTn&gt; = D/DT.fromordinal(&lt;int&gt;) <span class="hljs-comment"># D/DTn from days since Christ.</span>
616-
&lt;DTa&gt; = DT.fromtimestamp(&lt;real&gt;, &lt;tz&gt;) <span class="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
619+
&lt;DTa&gt; = DT.fromtimestamp(&lt;real&gt;, &lt;tz.&gt;) <span class="hljs-comment"># DTa from seconds since Epoch in tz time.</span>
617620
</code></pre>
618621
<ul>
619622
<li><strong>ISO strings come in following forms: <code class="python hljs"><span class="hljs-string">'YYYY-MM-DD'</span></code>, <code class="python hljs"><span class="hljs-string">'HH:MM:SS.ffffff[±&lt;offset&gt;]'</span></code>, or both separated by <code class="python hljs"><span class="hljs-string">'T'</span></code>. Offset is formatted as: <code class="python hljs"><span class="hljs-string">'HH:MM'</span></code>.</strong></li>
@@ -631,11 +634,15 @@ <h3 id="format-1">Format</h3>
631634
<span class="hljs-meta">&gt;&gt;&gt; </span>dt.strftime(<span class="hljs-string">"%A, %dth of %B '%y, %I:%M%p %Z"</span>)
632635
<span class="hljs-string">"Thursday, 14th of May '15, 11:39PM UTC+02:00"</span>
633636
</code></pre>
634-
<h4 id="restofthecodes">Rest of the codes:</h4>
635637
<ul>
636-
<li><strong><code class="python hljs"><span class="hljs-string">'a'</span></code> - Weekday, abbreviated name.</strong></li>
637-
<li><strong><code class="python hljs"><span class="hljs-string">'b'</span></code> - Month, abbreviated name.</strong></li>
638+
<li><strong>For abbreviated weekday and month use <code class="python hljs"><span class="hljs-string">'%a'</span></code> and <code class="python hljs"><span class="hljs-string">'%b'</span></code>.</strong></li>
638639
</ul>
640+
<h3 id="arithmetics">Arithmetics</h3>
641+
<pre><code class="python language-python apache hljs">&lt;D/DT&gt; = &lt;D/DT&gt; ± &lt;TD&gt;
642+
&lt;TD&gt; = &lt;TD&gt; ± &lt;TD&gt;
643+
&lt;TD&gt; = &lt;TD&gt; */ &lt;real&gt;
644+
&lt;float&gt; = &lt;TD&gt; / &lt;TD&gt;
645+
</code></pre>
639646
<h2 id="arguments"><a href="#arguments" name="arguments">#</a>Arguments</h2>
640647
<h3 id="insidefunctioncall">Inside Function Call</h3>
641648
<pre><code class="python language-python hljs">&lt;function&gt;(&lt;positional_args&gt;) <span class="hljs-comment"># f(0, 0)</span>
@@ -1209,7 +1216,7 @@ <h3 id="pathlib">Pathlib</h3>
12091216
&lt;bool&gt; = &lt;Path&gt;.is_file()
12101217
&lt;bool&gt; = &lt;Path&gt;.is_dir()
12111218
</code></pre>
1212-
<pre><code class="python language-python hljs">&lt;iter&gt; = &lt;Path&gt;.iterdir() <span class="hljs-comment"># Iterator with filenames located at path.</span>
1219+
<pre><code class="python language-python hljs">&lt;iter&gt; = &lt;Path&gt;.iterdir() <span class="hljs-comment"># Iterator of filenames located at path.</span>
12131220
&lt;iter&gt; = &lt;Path&gt;.glob(<span class="hljs-string">'&lt;pattern&gt;'</span>) <span class="hljs-comment"># Filenames matching the wildcard pattern.</span>
12141221
</code></pre>
12151222
<pre><code class="python language-python hljs">&lt;str&gt; = str(&lt;Path&gt;) <span class="hljs-comment"># Returns path as a string.</span>

0 commit comments

Comments
 (0)