blob: 6b4c1ecc43dd288d54534e898e17e93dd614964e [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _GeneralizedTime_H_
6#define _GeneralizedTime_H_
7
vlmfa67ddc2004-06-03 03:38:44 +00008#include <OCTET_STRING.h>
9
vlmd1579582004-09-24 21:00:50 +000010typedef OCTET_STRING_t GeneralizedTime_t; /* Implemented via OCTET STRING */
vlmfa67ddc2004-06-03 03:38:44 +000011
vlmef6355b2004-09-29 13:26:15 +000012extern asn_TYPE_descriptor_t asn_DEF_GeneralizedTime;
vlmfa67ddc2004-06-03 03:38:44 +000013
vlm39ba4c42004-09-22 16:06:28 +000014asn_struct_print_f GeneralizedTime_print;
vlmfa67ddc2004-06-03 03:38:44 +000015asn_constr_check_f GeneralizedTime_constraint;
vlm81057a82004-08-07 03:52:26 +000016der_type_encoder_f GeneralizedTime_encode_der;
vlm39ba4c42004-09-22 16:06:28 +000017xer_type_encoder_f GeneralizedTime_encode_xer;
vlmfa67ddc2004-06-03 03:38:44 +000018
19/***********************
20 * Some handy helpers. *
21 ***********************/
22
vlmfa67ddc2004-06-03 03:38:44 +000023struct tm; /* <time.h> */
vlm81057a82004-08-07 03:52:26 +000024
25/*
26 * Convert a GeneralizedTime structure into time_t
27 * and optionally into struct tm.
28 * If as_gmt is given, the resulting _optional_tm4fill will have a GMT zone,
29 * instead of default local one.
30 * On error returns -1 and errno set to EINVAL
31 */
32time_t asn_GT2time(const GeneralizedTime_t *, struct tm *_optional_tm4fill,
33 int as_gmt);
34
vlm5ea810e2005-07-03 05:32:40 +000035/* A version of the above function also returning the fractions of seconds */
36time_t asn_GT2time_frac(const GeneralizedTime_t *,
vlmaa116962005-07-04 12:21:51 +000037 int *frac_value, int *frac_digits, /* (value / (10 ^ digits)) */
38 struct tm *_optional_tm4fill, int as_gmt);
39
40/*
41 * Another version returning fractions with defined precision
42 * For example, parsing of the time ending with ".1" seconds
43 * with frac_digits=3 (msec) would yield frac_value = 100.
44 */
45time_t asn_GT2time_prec(const GeneralizedTime_t *,
46 int *frac_value, int frac_digits,
vlm5ea810e2005-07-03 05:32:40 +000047 struct tm *_optional_tm4fill, int as_gmt);
48
vlm81057a82004-08-07 03:52:26 +000049/*
50 * Convert a struct tm into GeneralizedTime.
vlm5ea810e2005-07-03 05:32:40 +000051 * If _optional_gt is not given, this function will try to allocate one.
vlm81057a82004-08-07 03:52:26 +000052 * If force_gmt is given, the resulting GeneralizedTime will be forced
vlmef6355b2004-09-29 13:26:15 +000053 * into a GMT time zone (encoding ends with a "Z").
vlm81057a82004-08-07 03:52:26 +000054 * On error, this function returns 0 and sets errno.
55 */
vlm5ea810e2005-07-03 05:32:40 +000056GeneralizedTime_t *asn_time2GT(GeneralizedTime_t *_optional_gt,
57 const struct tm *, int force_gmt);
58GeneralizedTime_t *asn_time2GT_frac(GeneralizedTime_t *_optional_gt,
vlmaa116962005-07-04 12:21:51 +000059 const struct tm *, int frac_value, int frac_digits, int force_gmt);
vlmfa67ddc2004-06-03 03:38:44 +000060
61#endif /* _GeneralizedTime_H_ */