<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rutvij Raut on Medium]]></title>
        <description><![CDATA[Stories by Rutvij Raut on Medium]]></description>
        <link>https://medium.com/@rutvijraut?source=rss-a2809d77f0b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tFreIjq9SESMBg4v.jpg</url>
            <title>Stories by Rutvij Raut on Medium</title>
            <link>https://medium.com/@rutvijraut?source=rss-a2809d77f0b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:43:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rutvijraut/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ZULU MODULE IN PYTHON]]></title>
            <link>https://medium.com/tech-iiitg/zulu-module-in-python-8840f0447801?source=rss-a2809d77f0b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8840f0447801</guid>
            <category><![CDATA[arrow]]></category>
            <category><![CDATA[datetime]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[zulu]]></category>
            <dc:creator><![CDATA[Rutvij Raut]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 14:30:37 GMT</pubDate>
            <atom:updated>2020-06-04T14:30:37.009Z</atom:updated>
            <content:encoded><![CDATA[<p>Working with dates and times in programming can be cumbersome. Click <a href="https://realpython.com/python-datetime/"><strong>here</strong></a><strong> </strong>to know why. Luckily, you rarely need to implement these entangled features from the first line nowadays, since open-source modules are accessible and always there to assist you.</p><p>1. <strong>datetime</strong> module: It provides classes for controlling dates and times.</p><p>The datetime module gives three classes that majority people will use:</p><ul><li>datetime.date is a glorified date that accepts the Gregorian calendar and broadens unendingly into the future and past. This object stores the year, month, and day as attributes.</li><li>datetime.time is a glorified time that accepts that there are 86,400 seconds out of every day with no leap seconds. This object stores the hour, minute, second, microsecond, and time zone data.</li><li>datetime.datetime is a mix of the date class and the time class. It has all the characteristics of the two classes.</li></ul><p>There are many other functions available in this module, you can get complete details from the <a href="https://docs.python.org/3/library/datetime.html">documentation</a>.</p><p>2.<strong> arrow</strong> module :</p><p>Python Arrow module is a replacement library for datetime. It is Time zone aware &amp; UTC(Coordinated Universal Time) by default. It offers support for creating dates from arguments, timestamp etc. Without much of a stretch we can perform date time controls, changing over one time-region to another, move time to get future or past date, position date to string and parse a string to make date instance.</p><ul><li>arrow.now : It is used to get local time, date and timestamps.</li><li>arrow.utcnow : This gets the coordinated universal time long with the date and time stamp.</li><li>arrow.get : It is used to obtain a date from a timestamp, while parsing string to date and instantiating date from arguments.</li><li>to() : This function converts one timezone to another.</li><li>replace() and shift() : These functions can be used to get future and past dates.</li></ul><p>Visit <a href="https://www.journaldev.com/23412/python-arrow-module">here</a> to know how to use these functions in code.</p><p>Click <a href="https://arrow.readthedocs.io/en/latest/">here</a> for detail documentation of the arrow module.</p><p>3.<strong> zulu</strong> module</p><p>Zulu module can be considered as an improved version for the popular datetime module and the arrow module. In this, all datetime objects changed over into UTC and also stored as UTC. It undertakes multiple string formatting using <a href="https://www.pythonforbeginners.com/strftime-and-strptime/">strptime and strftime directives</a> and <a href="https://help.scribesoft.com/scribeinsight/en/Subsystems/Insight/create_dts_files/manageconnections/textadapternew/date_time_formats.htm">Unicode date patterns</a>. This module can be installed by the command</p><pre> <strong><em>pip3 install zulu</em></strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*AdnkOynbjbTXWuiISFoEOg.png" /></figure><h4>Here are some features of the <strong><em>Zulu Module:</em></strong></h4><ul><li>It converts all the datetime objects and stores it as UTC .</li><li><a href="https://www.iso.org/iso-8601-date-and-time-format.html">ISO8601 formatted strings</a> and <a href="https://teamtreehouse.com/community/what-is-a-posix-timestamp-im-looking-for-its-definition-the-documentation-doesnt-explain-the-concept-behind-it">POSIX timestamps</a> are parsed by default.</li></ul><p>Take a look at the python code below :</p><pre><strong><em>import zulu</em></strong></pre><pre><strong><em># Zulu objects </em></strong></pre><pre><em>print(“when we pass timezone: ”,</em></pre><pre><em>zulu.parse(‘2020–06–02T16:10:15.708064+00:00’))</em></pre><pre><em>print(“when only date is passed:”,</em></pre><pre><em>zulu.parse(‘2020–06–02’))</em></pre><pre><em>print(“when we pass date and time both:”,</em></pre><pre><em>zulu.parse(‘2020–06–02 16:10’))</em></pre><pre><em>print(“when ISO8601 is passed as formats:”,</em></pre><pre><em>zulu.parse(‘2020–06–02T16:10:15.708064+00:00’,zulu.ISO8601))</em></pre><pre><em>print(“when we use Default timezone:”,</em></pre><pre><em>zulu.parse(‘2020–06–02’,default_tz =’US/Eastern’))</em></pre><p>The output for above mentioned code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*RvttmE6EiW0vdWSxb45HQQ.png" /></figure><ul><li>The Time zone representation applied when casting to native datetime object and while string output formatting only.</li><li>Provision of Drop-in replacement for native datetime objects.</li><li>It supports Python 3.4+.</li></ul><p>Take a tour of some commonly used Zulu classes and their implementations below.</p><pre><strong>import</strong> <strong>zulu</strong><br><br>zulu.now()<br><em># &lt;Zulu [2020-06-02T19:33:18.137493+00:00]&gt;</em><br><br>dt = zulu.parse(&#39;2020-06-02T19:33:18.137493+00:00&#39;)<br><em># &lt;Zulu [2020-06-02T19:33:18.137493+00:00]&gt;</em><br><br>dt = zulu.create(2020, 6, 02, 19, 33, 18, 137493)<br><em># &lt;Zulu [2020-06-02T19:33:18.137493+00:00]&gt;</em><br><br>dt.isoformat()<br><em># &#39;2020-06-02T19:33:18.137493+00:00&#39;</em><br><br>dt.timestamp()<br><em># 1469475198.137493</em><br><br>dt.naive<br><em># datetime.datetime(2020, 6, 02, 19, 33, 18, 137493)</em><br><br>dt.datetime<br><em># datetime.datetime(2020, 6, 02, 19, 33, 18, 137493, tzinfo=&lt;UTC&gt;)</em><br><br>dt.format(&#39;%Y-%m-<em>%d</em>&#39;)<br><em># 2020-06-02</em><br><br>dt.format(&#39;YYYY-MM-dd&#39;)<br><em># 2020-06-02</em><br><br>dt.format(&quot;E, MMM d, &#39;&#39;YY&quot;)<br><em># &quot;Mon, Jun 02, &#39;20&quot;</em><br><br>dt.format(&quot;E, MMM d, &#39;&#39;YY&quot;, locale=&#39;de&#39;)<br><em># &quot;Mo., Juni 02, &#39;20&quot;</em><br><br>dt.format(&quot;E, MMM d, &#39;&#39;YY&quot;, locale=&#39;fr&#39;)<br><em># &quot;lun., juin. 02, &#39;16&quot;</em><br><br>dt.shift(hours=-5, minutes=10)<br><em># &lt;Zulu [2020-06-02T14:43:18.137493+00:00]&gt;</em><br><br>dt.replace(hour=14, minute=43)<br><em># &lt;Zulu [2020-06-02T14:43:18.137493+00:00]&gt;</em><br><br>dt.start_of(&#39;day&#39;)<br><em># &lt;Zulu [2020-06-02T00:00:00+00:00]&gt;</em><br><br>dt.end_of(&#39;day&#39;)<br><em># &lt;Zulu [2020-06-02T23:59:59.999999+00:00]&gt;</em><br><br>dt.span(&#39;hour&#39;)<br><em># (&lt;Zulu [2020-06-02T19:00:00+00:00]&gt;, &lt;Zulu [2020-06-02T19:59:59.999999+00:00]&gt;)</em><br><br>dt.time_from(dt.end_of(&#39;day&#39;))<br><em># &#39;4 hours ago&#39;</em><br><br>dt.time_to(dt.end_of(&#39;day&#39;))<br><em># &#39;in 4 hours&#39;</em><br><br>list(zulu.range(&#39;hour&#39;, dt, dt.shift(hours=4)))<br><em># [Zulu [2020-06-02T19:33:18.137493+00:00]&gt;,</em><br><em>#  Zulu [2020-06-02T20:33:18.137493+00:00]&gt;,</em><br><em>#  Zulu [2020-06-02T21:33:18.137493+00:00]&gt;,</em><br><em>#  Zulu [2020-06-02T22:33:18.137493+00:00]&gt;]</em><br><br>list(zulu.span_range(&#39;minute&#39;, dt, dt.shift(minutes=4)))<br><em># [(Zulu [2020-06-02T19:33:00+00:00]&gt;, Zulu [2020-06-02T19:33:59.999999+00:00]&gt;),</em><br><em>#  (Zulu [2020-06-02T19:34:00+00:00]&gt;, Zulu [2020-06-02T19:34:59.999999+00:00]&gt;),</em><br><em>#  (Zulu [2020-06-02T19:35:00+00:00]&gt;, Zulu [2020-06-02T19:35:59.999999+00:00]&gt;),</em><br><em>#  (Zulu [2020-06-02T19:36:00+00:00]&gt;, Zulu [2020-06-02T19:36:59.999999+00:00]&gt;)]</em><br><br>zulu.parse_delta(&#39;1w 3d 2h 32m&#39;)<br><em># &lt;Delta [10 days, 2:32:00]&gt;</em><br><br>zulu.parse_delta(&#39;2:04:13:02.266&#39;)<br><em># &lt;Delta [2 days, 4:13:02.266000]&gt;</em><br><br>zulu.parse_delta(&#39;2 days, 5 hours, 34 minutes, 56 seconds&#39;)<br><em># &lt;Delta [2 days, 5:34:56]&gt;</em></pre><h4>Let’s take a look at the advantages of this module over the popular <strong><em>datetime module.</em></strong></h4><ul><li>Zulu has python-dateutil time zone support. Also it has a coterie of extended datetime features such as parse(), format(), shift().</li></ul><p>Take a look at the code provided below :</p><pre><strong>import zulu</strong></pre><pre>dt = zulu.parse(‘2020–06–02T16:10:15.708064+00:00’)</pre><pre>print(“The Datetime string without timezone is:”,</pre><pre>dt.format(‘% m/% d/% y % H:% M:% S % z’))</pre><pre>print(“The Datetime string without timezone is:”,</pre><pre>dt.format(‘MM / dd / YY HH:mm:ss Z’))</pre><pre>print(“The Datetime string when timezone is given is:”,</pre><pre>dt.format(‘% Y-% m-% d % H:% M:% S % z’,</pre><pre>tz =’US/Eastern’))</pre><pre>print(“The Datetime string when timezone is given as local is:”,</pre><pre>dt.format(‘%Y-%m-%d %H:%M:%S %z’,</pre><pre>tz =’local’))</pre><pre>#shift() used here                           </pre><pre>dt = zulu.parse(‘2020–06–02T16:10:15.708064+00:00’)</pre><pre>shifted1 = dt.shift(hours =-5, minutes = 10)</pre><pre>print(“The shifted time is:”, shifted1)</pre><pre>shifted2 = dt.shift(minutes = 55, seconds = 11,</pre><pre>microseconds = 10)</pre><pre>print(“The new shifted time is:”, shifted2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*ojKxaPOhIH2yr3SVGAxThw.png" /><figcaption>output of the above mentioned code.</figcaption></figure><ul><li>It Parses ISO8601 and timestamps naturally with no additional arguments.</li><li>It is Simpler to reason about Zulu objects as they are just UTC datetimes.</li><li>Zulu provides Clear description between UTC and other time zones where time zone representation can only be used for displaying datetime or transformation to native datetime.</li><li>It Supports more string parsing/formatting choices including Unicode date designs as well as strptime/strftime orders.</li></ul><h4>Let’s take a look at the advantages of this module over the <strong><em>arrow module.</em></strong></h4><ul><li>Zulu is a drop-in swap for local datetimes (acquired from datetime.datetime). Zulu is always a datetime hence it is not essential to convert using arrow.datetime.</li><li>It provides stricter parsing to stay away from quiet errors. For instance, one may expect</li></ul><pre>arrow.get(‘06/03/2020’, ‘MM/DD/YY’) </pre><p>to fail (“input does not match format” error) but it readily returns &lt;Arrow[2020–06–03T00:00:00+00:00) while</p><pre>zulu.parse(‘06/03/2020’, ‘%m/%d/%y’) </pre><p>returns zulu.parser.ParseError: Value “06/03/2020” does not match any format in [‘%m/%d/%y’].</p><ul><li>It also Avoids timezone/<a href="https://computer.howstuffworks.com/dst-bug.htm">DST shifting bugs</a> by possibly managing UTC datetimes while applying timedeltas or performing different calculations.</li><li>It Supports Unicode date patterns for string parsing/formatting and strptime/strftime.</li></ul><p><strong>Some Important Links for this module:</strong></p><p>• Project: <a href="https://github.com/dgilland/zulu">https://github.com/dgilland/zulu</a></p><p>• Documentation: <a href="https://zulu.readthedocs.io/">https://zulu.readthedocs.io/</a></p><p>• PyPI: <a href="https://pypi.python.org/pypi/zulu/">https://pypi.python.org/pypi/zulu/</a></p><p>• TravisCI: <a href="https://travis-ci.org/dgilland/zulu">https://travis-ci.org/dgilland/zulu</a></p><p><strong>Thank you for reading this till the end.</strong></p><p><strong>Thanks a lot !!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8840f0447801" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-iiitg/zulu-module-in-python-8840f0447801">ZULU MODULE IN PYTHON</a> was originally published in <a href="https://medium.com/tech-iiitg">tech@iiit-gwalior</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>