File: jstrptime.3

package info (click to toggle)
jcal 0.5.1-0.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,560 kB
  • sloc: ansic: 2,124; javascript: 1,370; python: 815; makefile: 202; sh: 186
file content (207 lines) | stat: -rw-r--r-- 5,756 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
.\" * jstrftime.3 - Tools for manipulating Jalali representation of Iranian calendar
.\" * and necessary conversations to Gregorian calendar.
.\" * Copyright (C) 2006, 2007, 2009, 2010, 2011 Ashkan Ghassemi.
.\" *
.\" * This file is part of libjalali.
.\" *
.\" * libjalali is free software: you can redistribute it and/or modify
.\" * it under the terms of the GNU Lesser General Public License as published by
.\" * the Free Software Foundation, either version 3 of the License, or
.\" * (at your option) any later version.
.\" *
.\" * libjalali is distributed in the hope that it will be useful,
.\" * but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" * GNU Lesser General Public License for more details.
.\" *
.\" * You should have received a copy of the GNU Lesser General Public License
.\" * along with libjalali.  If not, see <http://www.gnu.org/licenses/>.

.TH JSTRPTIME 3 2011-05-28 "GNU" "libjalali Manual"
.SH NAME
jstrptime \- convert a string representation of jalali date and time to a jalali time jtm structure
.SH SYNOPSIS
.B #include <time.h>
.sp
.BI "char *jstrptime(const char *" s ", const char *" format ,
.BI "struct jtm *" jtm );
.sp
Link with -ljalali
.SH DESCRIPTION
The
.BR jstrptime ()
function is the converse function to
.BR jstrftime (3)
and converts the character string pointed to by
.I s
to values which are stored in the
.I jtm
structure pointed to by
.IR jtm ,
using the format specified by
.IR format .
Here
.I format
is a character string that consists of field descriptors and text characters,
reminiscent of
.BR scanf (3).
Each field descriptor consists of a
.B %
character followed by another character that specifies the replacement
for the field descriptor.
All other characters in the
.I format
string must have a matching character in the input string.
There should be white\%space or other alphanumeric characters
between any two field descriptors.
.PP
The
.BR jstrptime ()
function processes the input string from left
to right.
Each of the three possible input elements (whitespace,
literal, or format) are handled one after the other.
If the input cannot be matched to the format string the function stops.
The remainder of the format and input strings are not processed.
.PP
The supported input field descriptors are listed below.
In case a text string (such as a weekday or month name)
is to be matched, the comparison is case insensitive.
In case a number is to be matched, leading zeros are
permitted but not required.
.TP
.B %%
The
.B %
character.
.TP
.BR %a " or " %A " or " %h " or " %q
The weekday name in abbreviated form or the full name.
.TP
.BR %b " or " %B
The month name in abbreviated form or the full name.
.TP
.BR %d " or " %e
The day of month (1-31).
.TP
.B %H
The hour (0-23).
.TP
.B %j
The day number in the year (1-366).
.TP
.B %m
The month number (1-12).
.TP
.B %M
The minute (0-59).
.TP
.B %s
Seconds since UTC Epoch.
.TP
.B %S
The second (0-59).
.TP
.B %y
The year within century (0-99).
When a century is not otherwise specified, values in the range 19-99 refer
to years in the fourteenth century (1319-1399); values in the
range 00-18 refer to years in the fifteenth century (1400-1418).
.TP
.B %Y
The year, including century (for example, 1390).
.LP
The broken-down jalali time structure \fIjtm\fP is defined in \fI<jtime.h>\fP
as follows:
.sp
.in +4n
.nf
struct jtm {
    int tm_sec;        /* seconds */
    int tm_min;        /* minutes */
    int tm_hour;       /* hours */
    int tm_mday;       /* day of the month */
    int tm_mon;        /* month */
    int tm_year;       /* year */
    int tm_wday;       /* day of the week */
    int tm_yday;       /* day in the year */
    int tm_isdst;      /* daylight saving time */
};
.fi
.in
.SH "RETURN VALUE"
The return value of the function is a pointer to the first character
not processed in this function call.
In case the input string
contains more characters than required by the format string the return
value points right after the last consumed input character.
In case
the whole input string is consumed the return value points to the null
byte at the end of the string.
If
.BR jstrptime ()
fails to match all
of the format string and therefore an error occurred the function
returns NULL.
.SH "CONFORMING TO"
C99.
.SH NOTES
.LP
In principle, this function does not initialize \fIjtm\fP but
only stores the values specified.
This means that \fIjtm\fP should be initialized before the call.
libjalali does not touch those fields which are not
explicitly specified.

.SH EXAMPLE
The following example demonstrates the use of
.BR jstrptime (3)
and
.BR jstrftime (3).
.sp
.nf
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <jalali.h>
#include <jtime.h>

int
main(void)
{
    struct jtm tm;
    char buf[255];

    memset(&jtm, 0, sizeof(struct jtm));
    jstrptime("1390\-03\-17 08:33:01", "%Y\-%m\-%d %H:%M:%S", &jtm);
    jstrftime(buf, sizeof(buf), "%d %b %Y %H:%M", &jtm);
    puts(buf);
    exit(EXIT_SUCCESS);
}
.fi
.SH "SEE ALSO"
.BR time (2),
.BR jdate (1),
.BR jcal (1),
.BR getdate (3),
.BR scanf (3),
.BR jstrftime (3),
.BR jctime (3),
.BR feature_test_macros (7)
.SH COLOPHON
This page is part of release 0.2 of the libjalali
.I man-pages
.SH AUTHOR
Written by Ashkan Ghassemi. <ghassemi@ftml.net>
.SH REPORTING BUGS
Report libjalali bugs to <ghassemi@ftml.net>

libjalali home page: <http://savannah.nongnu.org/projects/jcal/>
.SH COPYRIGHT
Copyright (C) 2011 Ashkan Ghassemi.

License LGPLv3+: GNU LGPL version 3 or later
<http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by
law.