YAZ  5.23.1
z-date.c
Go to the documentation of this file.
1 
6 #if HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 
10 #include <yaz/z-date.h>
11 
12 int z_DateTime(ODR o, Z_DateTime **p, int opt, const char *name)
13 {
14  if (!odr_sequence_begin(o, p, sizeof(**p), name))
15  return odr_missing(o, opt, name) && odr_ok (o);
16  return
18  &(*p)->date, ODR_CONTEXT, 1, 1, "date") &&
20  &(*p)->time, ODR_CONTEXT, 2, 1, "time") &&
22 }
23 
24 int z_DateMonthAndDay(ODR o, Z_DateMonthAndDay **p, int opt, const char *name)
25 {
26  if (!odr_sequence_begin(o, p, sizeof(**p), name))
27  return odr_missing(o, opt, name) && odr_ok (o);
28  return
30  &(*p)->month, ODR_CONTEXT, 2, 0, "month") &&
32  &(*p)->day, ODR_CONTEXT, 3, 1, "day") &&
34 }
35 
36 int z_DateQuarter(ODR o, Z_DateQuarter **p, int opt, const char *name)
37 {
38  static Odr_arm arm[] = {
40  (Odr_fun) odr_null, "first"},
42  (Odr_fun) odr_null, "second"},
44  (Odr_fun) odr_null, "third"},
46  (Odr_fun) odr_null, "fourth"},
47  {-1, -1, -1, -1, (Odr_fun) 0, 0}
48  };
49  if (!odr_initmember(o, p, sizeof(**p)))
50  return odr_missing(o, opt, name);
51  if (odr_choice(o, arm, &(*p)->u, &(*p)->which, name))
52  return 1;
53  if (o->direction == ODR_DECODE)
54  *p = 0;
55  return odr_missing(o, opt, name);
56 }
57 
58 int z_DateSeason(ODR o, Z_DateSeason **p, int opt, const char *name)
59 {
60  static Odr_arm arm[] = {
62  (Odr_fun) odr_null, "winter"},
64  (Odr_fun) odr_null, "spring"},
66  (Odr_fun) odr_null, "summer"},
68  (Odr_fun) odr_null, "autumn"},
69  {-1, -1, -1, -1, (Odr_fun) 0, 0}
70  };
71  if (!odr_initmember(o, p, sizeof(**p)))
72  return odr_missing(o, opt, name);
73  if (odr_choice(o, arm, &(*p)->u, &(*p)->which, name))
74  return 1;
75  if (o->direction == ODR_DECODE)
76  *p = 0;
77  return odr_missing(o, opt, name);
78 }
79 
80 int z_Era(ODR o, Z_Era **p, int opt, const char *name)
81 {
82  static Odr_arm arm[] = {
84  (Odr_fun) odr_null, "decade"},
86  (Odr_fun) odr_null, "century"},
88  (Odr_fun) odr_null, "millennium"},
89  {-1, -1, -1, -1, (Odr_fun) 0, 0}
90  };
91  if (!odr_initmember(o, p, sizeof(**p)))
92  return odr_missing(o, opt, name);
93  if (odr_choice(o, arm, &(*p)->u, &(*p)->which, name))
94  return 1;
95  if (o->direction == ODR_DECODE)
96  *p = 0;
97  return odr_missing(o, opt, name);
98 }
99 
100 int z_DateFlags(ODR o, Z_DateFlags **p, int opt, const char *name)
101 {
102  if (!odr_sequence_begin(o, p, sizeof(**p), name))
103  return odr_missing(o, opt, name) && odr_ok (o);
104  return
106  &(*p)->circa, ODR_CONTEXT, 1, 1, "circa") &&
108  &(*p)->era, ODR_CONTEXT, 2, 1, "era") &&
109  odr_sequence_end(o);
110 }
111 
112 int z_Date(ODR o, Z_Date **p, int opt, const char *name)
113 {
114  static Odr_arm arm[] = {
116  (Odr_fun) z_DateMonthAndDay, "monthAndDay"},
118  (Odr_fun) odr_integer, "julianDay"},
120  (Odr_fun) odr_integer, "weekNumber"},
122  (Odr_fun) z_DateQuarter, "quarter"},
124  (Odr_fun) z_DateSeason, "season"},
125  {-1, -1, -1, -1, (Odr_fun) 0, 0}
126  };
127  if (!odr_sequence_begin(o, p, sizeof(**p), name))
128  return odr_missing(o, opt, name) && odr_ok (o);
129  return
131  &(*p)->year, ODR_CONTEXT, 1, 0, "year") &&
132  ((odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 2, "partOfYear") &&
133  odr_choice(o, arm, &(*p)->u, &(*p)->which, 0) &&
134  odr_constructed_end(o)) || odr_ok(o)) &&
136  &(*p)->flags, ODR_CONTEXT, 3, 1, "flags") &&
137  odr_sequence_end(o);
138 }
139 
140 int z_Time(ODR o, Z_Time **p, int opt, const char *name)
141 {
142  static Odr_arm arm[] = {
144  (Odr_fun) odr_null, "local"},
146  (Odr_fun) odr_null, "utc"},
148  (Odr_fun) odr_integer, "utcOffset"},
149  {-1, -1, -1, -1, (Odr_fun) 0, 0}
150  };
151  if (!odr_sequence_begin(o, p, sizeof(**p), name))
152  return odr_missing(o, opt, name) && odr_ok (o);
153  return
155  &(*p)->hour, ODR_CONTEXT, 1, 0, "hour") &&
157  &(*p)->minute, ODR_CONTEXT, 2, 1, "minute") &&
159  &(*p)->second, ODR_CONTEXT, 3, 1, "second") &&
161  &(*p)->partOfSecond, ODR_CONTEXT, 4, 1, "partOfSecond") &&
162  odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 5, "zone") &&
163  odr_choice(o, arm, &(*p)->u, &(*p)->which, 0) &&
164  odr_constructed_end(o) &&
165  odr_sequence_end(o);
166 }
#define odr_ok(o)
Definition: odr.h:215
int z_Time(ODR o, Z_Time **p, int opt, const char *name)
Definition: z-date.c:140
#define Z_Time_utcOffset
Definition: z-date.h:130
#define odr_explicit_tag(o, t, p, cl, tg, opt, name)
Definition: odr.h:195
#define Z_Era_century
Definition: z-date.h:90
int z_DateSeason(ODR o, Z_DateSeason **p, int opt, const char *name)
Definition: z-date.c:58
#define Z_DateQuarter_third
Definition: z-date.h:64
int z_DateMonthAndDay(ODR o, Z_DateMonthAndDay **p, int opt, const char *name)
Definition: z-date.c:24
#define Z_Time_local
Definition: z-date.h:128
#define odr_implicit_tag(o, t, p, cl, tg, opt, name)
Definition: odr.h:192
int odr_sequence_begin(ODR o, void *p, int size, const char *name)
Definition: odr_seq.c:15
#define Z_Date_weekNumber
Definition: z-date.h:111
char * name
Definition: initopt.c:18
int z_DateQuarter(ODR o, Z_DateQuarter **p, int opt, const char *name)
Definition: z-date.c:36
#define Z_DateSeason_spring
Definition: z-date.h:77
#define Z_Time_utc
Definition: z-date.h:129
Definition: z-date.h:100
#define Z_Date_quarter
Definition: z-date.h:112
int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag, const char *name)
Definition: odr_cons.c:24
int odr_initmember(ODR o, void *p, int size)
Definition: odr_tag.c:44
int z_DateTime(ODR o, Z_DateTime **p, int opt, const char *name)
Definition: z-date.c:12
#define Z_DateQuarter_second
Definition: z-date.h:63
int direction
Definition: odr.h:126
#define Z_DateQuarter_fourth
Definition: z-date.h:65
int odr_integer(ODR o, Odr_int **p, int opt, const char *name)
Definition: odr_int.c:19
Definition: z-date.h:83
#define Z_DateQuarter_first
Definition: z-date.h:62
int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp, const char *name)
Definition: odr_choice.c:17
#define Z_Era_decade
Definition: z-date.h:89
#define ODR_EXPLICIT
Definition: odr.h:60
int(* Odr_fun)(ODR, char **, int, const char *)
Definition: odr.h:135
#define Z_DateSeason_summer
Definition: z-date.h:78
int which
Definition: odr.h:142
Definition: odr.h:137
#define Z_Date_julianDay
Definition: z-date.h:110
#define Z_Era_millennium
Definition: z-date.h:91
int odr_null(ODR o, Odr_null **p, int opt, const char *name)
Definition: odr_null.c:19
int odr_missing(ODR o, int opt, const char *name)
Definition: odr_util.c:82
Definition: odr.h:124
int odr_sequence_end(ODR o)
Definition: odr_seq.c:61
int opt
Definition: initopt.c:19
int z_Date(ODR o, Z_Date **p, int opt, const char *name)
Definition: z-date.c:112
ASN.1 Module UserInfoFormat-dateTime.
#define ODR_IMPLICIT
Definition: odr.h:59
#define Z_Date_monthAndDay
Definition: z-date.h:109
int z_Era(ODR o, Z_Era **p, int opt, const char *name)
Definition: z-date.c:80
int odr_constructed_end(ODR o)
Definition: odr_cons.c:148
#define Z_DateSeason_autumn
Definition: z-date.h:79
#define ODR_CONTEXT
Definition: odr.h:67
#define Z_Date_season
Definition: z-date.h:113
int z_IntUnit(ODR o, Z_IntUnit **p, int opt, const char *name)
Definition: z-core.c:1570
#define Z_DateSeason_winter
Definition: z-date.h:76
int z_DateFlags(ODR o, Z_DateFlags **p, int opt, const char *name)
Definition: z-date.c:100
#define ODR_DECODE
Definition: odr.h:95
Definition: z-date.h:118