]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/btime.h
Last major change for 1.27 code -- see kes13Nov02
[bacula/bacula] / bacula / src / lib / btime.h
1
2 /*  
3
4     Time and date structures and functions.
5     Date and time are always represented internally
6     as 64 bit floating point Julian day numbers and
7     fraction.  The day number and fraction are kept
8     as separate quantities to avoid round-off of
9     day fraction. John Walker
10
11      Version $Id$
12
13  */
14
15 /*
16    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
17
18    This program is free software; you can redistribute it and/or
19    modify it under the terms of the GNU General Public License as
20    published by the Free Software Foundation; either version 2 of
21    the License, or (at your option) any later version.
22
23    This program is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26    General Public License for more details.
27
28    You should have received a copy of the GNU General Public
29    License along with this program; if not, write to the Free
30    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
31    MA 02111-1307, USA.
32
33  */
34
35
36 #ifndef __btime_INCLUDED
37 #define __btime_INCLUDED
38
39 /* New btime definition -- use this */
40 extern btime_t get_current_btime(void);
41 extern time_t btime_to_unix(btime_t bt);   /* bacula time to epoch time */
42 extern utime_t btime_to_utime(btime_t bt); /* bacula time to utime_t */
43
44 extern void bstrftime(char *dt, int maxlen, utime_t tim);
45
46
47 /* =========================================================== */
48 /*        old code deprecated below. Do not use.               */
49
50 typedef float64_t fdate_t;             /* Date type */
51 typedef float64_t ftime_t;             /* Time type */
52
53 struct date_time {
54     fdate_t julian_day_number;         /* Julian day number */
55     ftime_t julian_day_fraction;       /* Julian day fraction */
56 };
57
58 /*  In arguments and results of the following functions,
59     quantities are expressed as follows.
60
61         year    Year in the Common Era.  The canonical
62                 date of adoption of the Gregorian calendar
63                 (October 5, 1582 in the Julian calendar)
64                 is assumed.
65
66         month   Month index with January 0, December 11.
67
68         day     Day number of month, 1 to 31.
69
70 */
71
72
73 extern fdate_t date_encode(uint32_t year, uint8_t month, uint8_t day);
74 extern ftime_t time_encode(uint8_t hour, uint8_t minute, uint8_t second,
75                           float32_t second_fraction);
76 extern void date_time_encode(struct date_time *dt,
77                              uint32_t year, uint8_t month, uint8_t day,
78                              uint8_t hour, uint8_t minute, uint8_t second,
79                              float32_t second_fraction);
80
81 extern void date_decode(fdate_t date, uint32_t *year, uint8_t *month,
82                         uint8_t *day);
83 extern void time_decode(ftime_t time, uint8_t *hour, uint8_t *minute,
84                         uint8_t *second, float32_t *second_fraction);
85 extern void date_time_decode(struct date_time *dt,
86                              uint32_t *year, uint8_t *month, uint8_t *day,
87                              uint8_t *hour, uint8_t *minute, uint8_t *second,
88                              float32_t *second_fraction);
89
90 extern int date_time_compare(struct date_time *dt1, struct date_time *dt2);
91
92 extern void tm_encode(struct date_time *dt, struct tm *tm);
93 extern void tm_decode(struct date_time *dt, struct tm *tm);
94 extern void get_current_time(struct date_time *dt);
95 extern utime_t str_to_utime(char *str);
96
97
98 #endif /* __btime_INCLUDED */