Skip to content

Commit a6dc0d7

Browse files
rose date: implement ISO 8601 support
1 parent f69afba commit a6dc0d7

File tree

14 files changed

+4426
-109
lines changed

14 files changed

+4426
-109
lines changed

bin/rose-date

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
# Specify a format for parsing DATE-TIME, which should
5252
# be compatible with the POSIX strptime template format (see
5353
# the strptime command help), with the following subset supported
54-
# across all date/time ranges: %F, %H, %M, %S, %Y, %d, %j, %m, %s, %y,
55-
# %z.
54+
# across all date/time ranges: %F, %H, %M, %S, %Y, %d, %j, %m, %s, %z.
5655
# If not specified, the system will attempt to parse DATE-TIME using
5756
# the following formats:
5857
# * ctime: "%a %b %d %H:%M:%S %Y"
@@ -66,13 +65,15 @@
6665
# as the parse format. Also support the isodatetime library dump
6766
# syntax which follows ISO 8601 example syntax - for example:
6867
# 'CCYY-MM-DDThh:mm:ss' -> '1955-11-05T09:28:00',
69-
# 'DD' -> '05',
7068
# 'CCYY' -> '1955',
7169
# 'CCYY-DDD' -> '1955-309',
7270
# 'CCYY-Www-D' -> '1955-W44-6'.
73-
# Note that specifying an explicit timezone in this format (e.g.
74-
# 'CCYY-MM-DDThh:mm:ss+0100' or 'CCYYDDDThhmmZ' will automatically
75-
# adapt the date/time to that timezone i.e. apply the correct hour/minute UTC offset.
71+
# Usage of this ISO 8601-like syntax should be as ISO 8601-compliant
72+
# as possible.
73+
# Note that specifying an explicit timezone in this format (e.g.
74+
# 'CCYY-MM-DDThh:mm:ss+0100' or 'CCYYDDDThhmmZ' will automatically
75+
# adapt the date/time to that timezone i.e. apply the correct
76+
# hour/minute UTC offset.
7677
# --use-task-cycle-time, -c
7778
# Shorthand for `rose date $ROSE_TASK_CYCLE_TIME`.
7879
# --utc, -u

doc/rose-command.html

+64-47
Original file line numberDiff line numberDiff line change
@@ -743,46 +743,55 @@ <h3>OPTIONS</h3>
743743
<dl>
744744
<dt><kbd>--offset=OFFSET</kbd>, <kbd>-s OFFSET</kbd></dt>
745745

746-
<dd><p>Specify an offset to add to the current or the specified <var>DATE-TIME</var>.
747-
<var>OFFSET</var> must follow the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> duration representations such as
748-
<var>PnW</var> or <var>PnYnMnDTnHnMnS</var> - <var>P</var> followed by a series
749-
of <var>nU</var> where <var>U</var> is the unit (<samp>Y</samp>,
750-
<samp>M</samp>, <samp>D</samp>, <samp>H</samp>, <samp>M</samp>,
751-
<samp>S</samp>) and <samp>n</samp> is a positive integer.
752-
<samp>n</samp> may also have a decimal (e.g. <samp>PT5.5M</samp>)
753-
part for a unit provided no smaller units are supplied. It is not
754-
necessary to specify zero values for units. If <var>OFFSET</var> is
755-
negative, prefix a <samp>-</samp>.
756-
For example:</p>
757-
<ul>
758-
<li><samp>P6D</samp> - 6 day offset</li>
759-
<li><samp>PT6H</samp> - 6 hour offset</li>
760-
<li><samp>PT1M</samp> - 1 minute offset</li>
761-
<li><samp>-PT1M</samp> - (negative) 1 minute offset</li>
762-
<li><samp>P3M</samp> - 1 month offset</li>
763-
<li><samp>P2W</samp> - 2 week offset (note no other units may be combined with weeks)</li>
764-
</ul>
765-
766-
<p>The following deprecated syntax is also supported:
767-
<var>OFFSET</var> in the form <var>nU</var>
768-
where <var>U</var> is the unit (<kbd>w</kbd> for weeks, <kbd>d</kbd> for
769-
days, <kbd>h</kbd> for hours, <kbd>m</kbd> for minutes and <kbd>s</kbd>
770-
for seconds) and <var>n</var> is an positive or negative integer.
771-
Multiple offsets can be specified with multiple
772-
<kbd>--offset=OFFSET</kbd> options.</p></dd>
746+
<dd>
747+
<p>Specify an offset to add to the current or the specified
748+
<var>DATE-TIME</var>. <var>OFFSET</var> must follow the <a href=
749+
"http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> duration
750+
representations such as <var>PnW</var> or <var>PnYnMnDTnHnMnS</var> -
751+
<var>P</var> followed by a series of <var>nU</var> where <var>U</var>
752+
is the unit (<samp>Y</samp>, <samp>M</samp>, <samp>D</samp>,
753+
<samp>H</samp>, <samp>M</samp>, <samp>S</samp>) and <samp>n</samp> is a
754+
positive integer. <samp>n</samp> may also have a decimal (e.g.
755+
<samp>PT5.5M</samp>) part for a unit provided no smaller units are
756+
supplied. It is not necessary to specify zero values for units. If
757+
<var>OFFSET</var> is negative, prefix a <samp>-</samp>. For
758+
example:</p>
759+
760+
<ul>
761+
<li><samp>P6D</samp> - 6 day offset</li>
762+
763+
<li><samp>PT6H</samp> - 6 hour offset</li>
764+
765+
<li><samp>PT1M</samp> - 1 minute offset</li>
766+
767+
<li><samp>-PT1M</samp> - (negative) 1 minute offset</li>
768+
769+
<li><samp>P3M</samp> - 1 month offset</li>
770+
771+
<li><samp>P2W</samp> - 2 week offset (note no other units may be
772+
combined with weeks)</li>
773+
</ul>
774+
775+
<p>The following deprecated syntax is also supported: <var>OFFSET</var>
776+
in the form <var>nU</var> where <var>U</var> is the unit (<kbd>w</kbd>
777+
for weeks, <kbd>d</kbd> for days, <kbd>h</kbd> for hours, <kbd>m</kbd>
778+
for minutes and <kbd>s</kbd> for seconds) and <var>n</var> is an
779+
positive or negative integer. Multiple offsets can be specified with
780+
multiple <kbd>--offset=OFFSET</kbd> options.</p>
781+
</dd>
773782

774783
<dt><kbd>--parse-format=FORMAT</kbd>, <kbd>-p FORMAT</kbd></dt>
775784

776785
<dd>
777-
Specify a format for parsing <var>DATE-TIME</var>, which should
778-
be compatible with the <a href="http://www.unix.com/man-page/POSIX/3posix/strptime/">POSIX strptime</a> template format (see
779-
the strptime command help), with the following subset supported
780-
across all date/time ranges: <samp>%F</samp>, <samp>%H</samp>,
781-
<samp>%M</samp>, <samp>%S</samp>, <samp>%Y</samp>, <samp>%d</samp>,
782-
<samp>%j</samp>, <samp>%m</samp>, <samp>%s</samp>, <samp>%y</samp>,
783-
<samp>%z</samp>.
784-
If not specified, the system will attempt to parse <var>DATE-TIME</var>
785-
using the following formats:
786+
Specify a format for parsing <var>DATE-TIME</var>, which should be
787+
compatible with the <a href=
788+
"http://www.unix.com/man-page/POSIX/3posix/strptime/">POSIX
789+
strptime</a> template format (see the strptime command help), with the
790+
following subset supported across all date/time ranges:
791+
<samp>%F</samp>, <samp>%H</samp>, <samp>%M</samp>, <samp>%S</samp>,
792+
<samp>%Y</samp>, <samp>%d</samp>, <samp>%j</samp>, <samp>%m</samp>,
793+
<samp>%s</samp>, <samp>%z</samp>. If not specified, the system will
794+
attempt to parse <var>DATE-TIME</var> using the following formats:
786795

787796
<ul>
788797
<li><dfn>ctime</dfn>: <samp>%a %b %d %H:%M:%S %Y</samp></li>
@@ -799,19 +808,27 @@ <h3>OPTIONS</h3>
799808
<dt><kbd>--print-format=FORMAT</kbd>, <kbd>--format=FORMAT</kbd>, <kbd>-f
800809
FORMAT</kbd></dt>
801810

802-
<dd><p>Specify a format for printing the result. Default to the same format
803-
as the parse format. Also support the isodatetime library dump
804-
syntax which is an adaptation of ISO 8601 example syntax - for example:</p>
811+
<dd>
812+
<p>Specify a format for printing the result. Default to the same format
813+
as the parse format. Also support the isodatetime library dump syntax
814+
which is an adaptation of ISO 8601 example syntax - for example:</p>
815+
805816
<ul>
806-
<li><samp>CCYY-MM-DDThh:mm:ss</samp> -> <samp>1955-11-05T09:28:00</samp></li>
807-
<li><samp>DD</samp> -> <samp>05</samp></li>
808-
<li><samp>CCYY</samp> -> <samp>1955</samp></li>
809-
<li><samp>CCYY-DDD</samp> -> <samp>1955-309</samp></li>
817+
<li><samp>CCYY-MM-DDThh:mm:ss</samp> -&gt;
818+
<samp>1955-11-05T09:28:00</samp></li>
819+
820+
<li><samp>DD</samp> -&gt; <samp>05</samp></li>
821+
822+
<li><samp>CCYY</samp> -&gt; <samp>1955</samp></li>
823+
824+
<li><samp>CCYY-DDD</samp> -&gt; <samp>1955-309</samp></li>
810825
</ul>
811-
<p>Note that specifying an explicit timezone in this format (e.g.
812-
<samp>CCYY-MM-DDThh:mm:ss+0100</samp> or <samp>CCYYDDDThhmmZ</samp> will automatically
813-
adapt the date/time to that timezone i.e. apply the correct
814-
hour/minute UTC offset.</p>
826+
827+
<p>Usage of this ISO 8601-like syntax should be as ISO 8601-compliant
828+
as possible. Note that specifying an explicit timezone in this format
829+
(e.g. <samp>CCYY-MM-DDThh:mm:ss+0100</samp> or
830+
<samp>CCYYDDDThhmmZ</samp> will automatically adapt the date/time to
831+
that timezone i.e. apply the correct hour/minute UTC offset.</p>
815832
</dd>
816833

817834
<dt><kbd>--use-task-cycle-time, -c</kbd></dt>

lib/python/isodatetime/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
#-----------------------------------------------------------------------------
3+
# (C) British Crown Copyright 2013-2014 Met Office.
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Lesser General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)