Ion C
C library for Ion
Loading...
Searching...
No Matches
ion_timestamp.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at:
7 *
8 * http://aws.amazon.com/apache2.0/
9 *
10 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12 * language governing permissions and limitations under the License.
13 */
14
17//
18// ion timestamp support routines
19// includes toString and Parse (in Java terms)
20//
21// overall format is (from ion wiki):
22//
23// null.timestamp // A null timestamp value
24//
25// 2007-02-23 // A day, equivalent to 2007-02-23T00:00:00-00:00
26// 2007-02-23T12:14Z // Seconds are optional, but timezone is not
27// 2007-02-23T12:14:33.079-08:00 // A timestamp with millisecond precision and PST local time
28// 2007-02-23T20:14:33.079Z // The same instant in UTC ("zero" or "zulu")
29// 2007-02-23T20:14:33.079+00:00 // The same instant with explicit local offset
30//
31
32#ifndef ION_TIMESTAMP_H_
33#define ION_TIMESTAMP_H_
34
35#include "ion_types.h"
36#include "ion_platform_config.h"
37#include "time.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
51 uint8_t precision;
52
56 int16_t tz_offset;
57 uint16_t year, month, day;
58 uint16_t hours, minutes, seconds;
59
63 decQuad fraction;
64};
65
66#define ION_TT_BIT_YEAR 0x01
67#define ION_TT_BIT_MONTH 0x02
68#define ION_TT_BIT_DAY 0x04
69#define ION_TT_BIT_MIN 0x10
70#define ION_TT_BIT_SEC 0x20 /* with secs must have time & date */
71#define ION_TT_BIT_FRAC 0x40 /* must have all */
72
73#define ION_TS_YEAR (0x0 | ION_TT_BIT_YEAR)
74#define ION_TS_MONTH (ION_TS_YEAR | ION_TT_BIT_MONTH)
75#define ION_TS_DAY (ION_TS_MONTH | ION_TT_BIT_DAY)
76#define ION_TS_MIN (ION_TS_DAY | ION_TT_BIT_MIN)
77#define ION_TS_SEC (ION_TS_MIN | ION_TT_BIT_SEC)
78#define ION_TS_FRAC (ION_TS_SEC | ION_TT_BIT_FRAC)
79
80#define ION_MAX_TIMESTAMP_STRING (26+DECQUAD_String) /* y-m-dTh:m:s.<dec>+h:m */ // TODO there is another definition of a similar constant in ion_debug.h that is shorter. Investigate.
81
87ION_API_EXPORT iERR ion_timestamp_get_precision(const ION_TIMESTAMP *ptime, int *precision);
88
92ION_API_EXPORT iERR ion_timestamp_to_string(ION_TIMESTAMP *ptime, char *buffer, SIZE buf_length,
93 SIZE *output_length, decContext *pcontext);
94
99ION_API_EXPORT iERR ion_timestamp_parse(ION_TIMESTAMP *ptime, char *buffer, SIZE length,
100 SIZE *p_characters_used, decContext *pcontext);
101
111ION_API_EXPORT iERR ion_timestamp_for_time_t(ION_TIMESTAMP *ptime, const time_t *time);
112
116ION_API_EXPORT iERR ion_timestamp_to_time_t(const ION_TIMESTAMP *ptime, time_t *time);
117
121ION_API_EXPORT iERR ion_timestamp_equals(const ION_TIMESTAMP *ptime1, const ION_TIMESTAMP *ptime2,
122 BOOL *is_equal, decContext *pcontext);
123
127ION_API_EXPORT iERR ion_timestamp_instant_equals(const ION_TIMESTAMP *ptime1, const ION_TIMESTAMP *ptime2,
128 BOOL *is_equal, decContext *pcontext);
129
138ION_API_EXPORT iERR ion_timestamp_for_year(ION_TIMESTAMP *ptime,
139 int year);
140
149ION_API_EXPORT iERR ion_timestamp_for_month(ION_TIMESTAMP *ptime,
150 int year, int month);
151
160ION_API_EXPORT iERR ion_timestamp_for_day(ION_TIMESTAMP *ptime,
161 int year, int month, int day);
162
171ION_API_EXPORT iERR ion_timestamp_for_minute(ION_TIMESTAMP *ptime,
172 int year, int month, int day, int hours, int minutes);
173
182ION_API_EXPORT iERR ion_timestamp_for_second(ION_TIMESTAMP *ptime,
183 int year, int month, int day, int hours, int minutes, int seconds);
184
195ION_API_EXPORT iERR ion_timestamp_for_fraction(ION_TIMESTAMP *ptime,
196 int year, int month, int day, int hours, int minutes, int seconds,
197 decQuad *p_fraction, decContext *pcontext);
198
201ION_API_EXPORT iERR ion_timestamp_get_thru_year(ION_TIMESTAMP *ptime, int *p_year);
202
207 int *p_year, int *p_month);
208
212ION_API_EXPORT iERR ion_timestamp_get_thru_day(ION_TIMESTAMP *ptime,
213 int *p_year, int *p_month, int *p_day);
214
219 int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute);
220
225 int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute, int *p_second);
226
231 int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute, int *p_second,
232 decQuad *p_fraction);
233
245ION_API_EXPORT iERR ion_timestamp_has_local_offset(ION_TIMESTAMP *ptime, BOOL *p_has_local_offset);
246
259ION_API_EXPORT iERR ion_timestamp_get_local_offset(ION_TIMESTAMP *ptime, int *p_offset_minutes);
260
271
285ION_API_EXPORT iERR ion_timestamp_set_local_offset(ION_TIMESTAMP *ptime, int offset_minutes);
286
287#ifdef __cplusplus
288}
289#endif
290
291#endif
ION_API_EXPORT iERR ion_timestamp_for_minute(ION_TIMESTAMP *ptime, int year, int month, int day, int hours, int minutes)
ION_API_EXPORT iERR ion_timestamp_get_thru_day(ION_TIMESTAMP *ptime, int *p_year, int *p_month, int *p_day)
ION_API_EXPORT iERR ion_timestamp_for_month(ION_TIMESTAMP *ptime, int year, int month)
ION_API_EXPORT iERR ion_timestamp_get_local_offset(ION_TIMESTAMP *ptime, int *p_offset_minutes)
ION_API_EXPORT iERR ion_timestamp_get_thru_year(ION_TIMESTAMP *ptime, int *p_year)
ION_API_EXPORT iERR ion_timestamp_for_year(ION_TIMESTAMP *ptime, int year)
ION_API_EXPORT iERR ion_timestamp_get_precision(const ION_TIMESTAMP *ptime, int *precision)
ION_API_EXPORT iERR ion_timestamp_get_thru_fraction(ION_TIMESTAMP *ptime, int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute, int *p_second, decQuad *p_fraction)
ION_API_EXPORT iERR ion_timestamp_get_thru_second(ION_TIMESTAMP *ptime, int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute, int *p_second)
ION_API_EXPORT iERR ion_timestamp_to_time_t(const ION_TIMESTAMP *ptime, time_t *time)
ION_API_EXPORT iERR ion_timestamp_equals(const ION_TIMESTAMP *ptime1, const ION_TIMESTAMP *ptime2, BOOL *is_equal, decContext *pcontext)
ION_API_EXPORT iERR ion_timestamp_parse(ION_TIMESTAMP *ptime, char *buffer, SIZE length, SIZE *p_characters_used, decContext *pcontext)
ION_API_EXPORT iERR ion_timestamp_has_local_offset(ION_TIMESTAMP *ptime, BOOL *p_has_local_offset)
ION_API_EXPORT iERR ion_timestamp_for_time_t(ION_TIMESTAMP *ptime, const time_t *time)
ION_API_EXPORT iERR ion_timestamp_unset_local_offset(ION_TIMESTAMP *ptime)
ION_API_EXPORT iERR ion_timestamp_for_second(ION_TIMESTAMP *ptime, int year, int month, int day, int hours, int minutes, int seconds)
ION_API_EXPORT iERR ion_timestamp_for_fraction(ION_TIMESTAMP *ptime, int year, int month, int day, int hours, int minutes, int seconds, decQuad *p_fraction, decContext *pcontext)
ION_API_EXPORT iERR ion_timestamp_get_thru_month(ION_TIMESTAMP *ptime, int *p_year, int *p_month)
ION_API_EXPORT iERR ion_timestamp_for_day(ION_TIMESTAMP *ptime, int year, int month, int day)
ION_API_EXPORT iERR ion_timestamp_set_local_offset(ION_TIMESTAMP *ptime, int offset_minutes)
ION_API_EXPORT iERR ion_timestamp_to_string(ION_TIMESTAMP *ptime, char *buffer, SIZE buf_length, SIZE *output_length, decContext *pcontext)
ION_API_EXPORT iERR ion_timestamp_get_thru_minute(ION_TIMESTAMP *ptime, int *p_year, int *p_month, int *p_day, int *p_hour, int *p_minute)
ION_API_EXPORT iERR ion_timestamp_instant_equals(const ION_TIMESTAMP *ptime1, const ION_TIMESTAMP *ptime2, BOOL *is_equal, decContext *pcontext)
Definition ion_timestamp.h:47
uint8_t precision
Definition ion_timestamp.h:51
int16_t tz_offset
Definition ion_timestamp.h:56
decQuad fraction
Definition ion_timestamp.h:63