1 |
/* PEAK Library |
2 |
* |
3 |
* Copyright (c) 2003, 2004 |
4 |
* Stephane Thiell <mbuna@bugged.org>. All rights reserved. |
5 |
* |
6 |
* Redistribution and use in source and binary forms, with or without |
7 |
* modification, are permitted provided that the following conditions |
8 |
* are met: |
9 |
* |
10 |
* 1. Redistributions of source code must retain the above copyright |
11 |
* notice, this list of conditions and the following disclaimer. |
12 |
* |
13 |
* 2. Redistributions in binary form must reproduce the above copyright |
14 |
* notice, this list of conditions and the following disclaimer in the |
15 |
* documentation and/or other materials provided with the distribution. |
16 |
* |
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
19 |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
22 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
24 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
25 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
26 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
27 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 |
* |
29 |
* $Id: time.h,v 1.2 2004/01/04 23:49:20 mbuna Exp $ |
30 |
*/ |
31 |
#ifndef INCLUDED_PEAK_TIME_H_ |
32 |
#define INCLUDED_PEAK_TIME_H_ |
33 |
|
34 |
/*! |
35 |
* @defgroup time Time |
36 |
* |
37 |
* This little Time module has been added in order to provide optimized |
38 |
* simple time related methods. Systems provide similar features but you |
39 |
* are invited to use PEAK's ones instead. |
40 |
*/ |
41 |
|
42 |
#include <peak/stdint.h> |
43 |
#include <peak/tz.h> |
44 |
#include <time.h> |
45 |
|
46 |
/*! |
47 |
* @ingroup time |
48 |
* @brief Gregorian date structure. |
49 |
* |
50 |
* Structure used to represent a date using the Gregorian calendar. |
51 |
*/ |
52 |
typedef struct |
53 |
{ |
54 |
/*! full year */ |
55 |
int32_t year; |
56 |
/*! month number 1-12 */ |
57 |
int8_t month; |
58 |
/*! day number 1-31 */ |
59 |
int8_t day; |
60 |
/*! hour 0-23 */ |
61 |
int8_t hour; |
62 |
/*! minute 0-59 */ |
63 |
int8_t minute; |
64 |
/*! second */ |
65 |
double second; |
66 |
} peak_time_date; |
67 |
|
68 |
#if defined(__cplusplus) |
69 |
extern "C" { |
70 |
#endif |
71 |
|
72 |
/*! |
73 |
* @ingroup time |
74 |
* @brief Get current time. |
75 |
* |
76 |
* @return The peak_time() function returns the value of time in seconds |
77 |
* since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated |
78 |
* Universal Time (the "epoch"). |
79 |
*/ |
80 |
extern time_t peak_time(void); |
81 |
|
82 |
/*! |
83 |
* @ingroup time |
84 |
* @brief Get current time with precision. |
85 |
* |
86 |
* @return The peak_time_float() function returns the value of time in |
87 |
* seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970, |
88 |
* Coordinated Universal Time (the "epoch"). |
89 |
*/ |
90 |
extern double peak_time_float(void); |
91 |
|
92 |
/*! |
93 |
* @ingroup time |
94 |
* @brief Converts an Unix time value into a Gregorian date. |
95 |
* |
96 |
* @param t Unix time value in second. Pass the result of peak_time_float() |
97 |
* to get current date. |
98 |
* @param tz Optional Time Zone reference. See peak_tz_create(). If provided, |
99 |
* necessary time zone's conversions will be performed. |
100 |
* |
101 |
* @return The Gregorian date equivalent for the specified time value since |
102 |
* 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated |
103 |
* Universal Time (the "epoch"). |
104 |
*/ |
105 |
extern peak_time_date peak_time_get_date(double t, peak_tz tz); |
106 |
|
107 |
#if defined(__cplusplus) |
108 |
} |
109 |
#endif |
110 |
|
111 |
#endif /* INCLUDED_PEAK_TIME_H_ */ |