annotate lib/parse-duration.h @ 17480:f40b3156a43e

selinux-at: omit unnecessary include * lib/selinux-at.c: Don't include dosname.h; not needed, since this source file doesn't use its macros, and subsidiary files that use the macros already include it.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 23 Aug 2013 13:53:46 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
1 /* Parse a time duration and return a seconds count
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16358
diff changeset
2 Copyright (C) 2008-2013 Free Software Foundation, Inc.
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
3 Written by Bruce Korb <bkorb@gnu.org>, 2008.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
4
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
8 (at your option) any later version.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
9
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
13 GNU General Public License for more details.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
14
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
17
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
18 /*
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
19
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
20 Readers and users of this function are referred to the ISO-8601
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
21 specification, with particular attention to "Durations".
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
22
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
23 At the time of writing, this worked:
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
24
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
25 http://en.wikipedia.org/wiki/ISO_8601#Durations
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
26
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
27 The string must start with a 'P', 'T' or a digit.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
28
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
29 ==== if it is a digit
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
30
10978
1780a93bb27f parse-duration: small doc tweak and coding aesthetics issue.
Bruce Korb <bkorb@gnu.org>
parents: 10890
diff changeset
31 the string may contain: NNN Y NNN M NNN W NNN d NNN h NNN m NNN s
1780a93bb27f parse-duration: small doc tweak and coding aesthetics issue.
Bruce Korb <bkorb@gnu.org>
parents: 10890
diff changeset
32 This represents NNN years, NNN months, NNN weeks, NNN days, NNN hours,
1780a93bb27f parse-duration: small doc tweak and coding aesthetics issue.
Bruce Korb <bkorb@gnu.org>
parents: 10890
diff changeset
33 NNN minutes and NNN seconds.
16358
a712776b11ce maint: spelling fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
34 The embedded white space is optional.
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
35 These terms must appear in this order.
10978
1780a93bb27f parse-duration: small doc tweak and coding aesthetics issue.
Bruce Korb <bkorb@gnu.org>
parents: 10890
diff changeset
36 Case is significant: 'M' is months and 'm' is minutes.
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
37 The final "s" is optional.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
38 All of the terms ("NNN" plus designator) are optional.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
39 Minutes and seconds may optionally be represented as NNN:NNN.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
40 Also, hours, minute and seconds may be represented as NNN:NNN:NNN.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
41 There is no limitation on the value of any of the terms, except
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
42 that the final result must fit in a time_t value.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
43
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
44 ==== if it is a 'P' or 'T', please see ISO-8601 for a rigorous definition.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
45
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
46 The 'P' term may be followed by any of three formats:
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
47 yyyymmdd
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
48 yy-mm-dd
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
49 yy Y mm M ww W dd D
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
50
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
51 or it may be empty and followed by a 'T'. The "yyyymmdd" must be eight
10890
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
52 digits long.
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
53
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
54 NOTE! Months are always 30 days and years are always 365 days long.
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
55 5 years is always 1825 days, not 1826 or 1827 depending on leap year
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
56 considerations. 3 months is always 90 days. There is no consideration
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
57 for how many days are in the current, next or previous months.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
58
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
59 For the final format:
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
60 * Embedded white space is allowed, but it is optional.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
61 * All of the terms are optional. Any or all-but-one may be omitted.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
62 * The meanings are yy years, mm months, ww weeks and dd days.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
63 * The terms must appear in this order.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
64
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
65 ==== The 'T' term may be followed by any of these formats:
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
66
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
67 hhmmss
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
68 hh:mm:ss
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
69 hh H mm M ss S
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
70
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
71 For the final format:
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
72 * Embedded white space is allowed, but it is optional.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
73 * All of the terms are optional. Any or all-but-one may be omitted.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
74 * The terms must appear in this order.
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
75
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
76 */
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
77 #ifndef GNULIB_PARSE_DURATION_H
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
78 #define GNULIB_PARSE_DURATION_H
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
79
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
80 #include <time.h>
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
81
10890
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
82 /* Return value when a valid duration cannot be parsed. */
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
83 #define BAD_TIME ((time_t)~0)
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
84
10890
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
85 /* Parses the given string. If it has the syntax of a valid duration,
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
86 this duration is returned. Otherwise, the return value is BAD_TIME,
195c41817bd2 parse-duration: various small improvements.
Bruno Haible <bruno@clisp.org>
parents: 10822
diff changeset
87 and errno is set to either EINVAL (bad syntax) or ERANGE (out of range). */
13051
094f6cfdb5c3 Minor formatting changes.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
88 extern time_t parse_duration (char const * in_pz);
10822
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
89
79d3d3250757 New module 'parse-duration'.
Bruce Korb <bkorb@gnu.org>
parents:
diff changeset
90 #endif /* GNULIB_PARSE_DURATION_H */