1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
5    Copyright (C) 2013-2018 Bareos GmbH & Co. KG
6 
7    This program is Free Software; you can redistribute it and/or
8    modify it under the terms of version three of the GNU Affero General Public
9    License as published by the Free Software Foundation and included
10    in the file LICENSE.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    Affero General Public License for more details.
16 
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21 */
22 
23 #ifndef BAREOS_LIB_BTIME_H_
24 #define BAREOS_LIB_BTIME_H_
25 
26 /* New btime definition -- use this */
27 btime_t GetCurrentBtime(void);
28 time_t BtimeToUnix(btime_t bt);   /* bareos time to epoch time */
29 utime_t BtimeToUtime(btime_t bt); /* bareos time to utime_t */
30 
31 int tm_wom(int mday, int wday);
32 int TmWoy(time_t stime);
33 
34 void Blocaltime(const time_t* time, struct tm* tm);
35 char* bstrutime(char* dt, int maxlen, utime_t tim);
36 char* bstrftime(char* dt, int maxlen, utime_t tim, const char* fmt = NULL);
37 char* bstrftimes(char* dt, int maxlen, utime_t tim);
38 char* bstrftime_ny(char* dt, int maxlen, utime_t tim);
39 char* bstrftime_nc(char* dt, int maxlen, utime_t tim);
40 char* bstrftime_wd(char* dt, int maxlen, utime_t tim);
41 utime_t StrToUtime(const char* str);
42 
43 
44 /* =========================================================== */
45 /*        old code deprecated below. Do not use.               */
46 
47 typedef float64_t fdate_t; /* Date type */
48 typedef float64_t ftime_t; /* Time type */
49 
50 struct date_time {
51   fdate_t julian_day_number;   /* Julian day number */
52   ftime_t julian_day_fraction; /* Julian day fraction */
53 };
54 
55 /*  In arguments and results of the following functions,
56     quantities are expressed as follows.
57 
58         year    Year in the Common Era.  The canonical
59                 date of adoption of the Gregorian calendar
60                 (October 5, 1582 in the Julian calendar)
61                 is assumed.
62 
63         month   Month index with January 0, December 11.
64 
65         day     Day number of month, 1 to 31.
66 
67 */
68 
69 
70 extern fdate_t DateEncode(uint32_t year, uint8_t month, uint8_t day);
71 extern ftime_t TimeEncode(uint8_t hour,
72                           uint8_t minute,
73                           uint8_t second,
74                           float32_t second_fraction);
75 extern void date_time_encode(struct date_time* dt,
76                              uint32_t year,
77                              uint8_t month,
78                              uint8_t day,
79                              uint8_t hour,
80                              uint8_t minute,
81                              uint8_t second,
82                              float32_t second_fraction);
83 
84 extern void DateDecode(fdate_t date,
85                        uint32_t* year,
86                        uint8_t* month,
87                        uint8_t* day);
88 extern void TimeDecode(ftime_t time,
89                        uint8_t* hour,
90                        uint8_t* minute,
91                        uint8_t* second,
92                        float32_t* second_fraction);
93 extern void date_time_decode(struct date_time* dt,
94                              uint32_t* year,
95                              uint8_t* month,
96                              uint8_t* day,
97                              uint8_t* hour,
98                              uint8_t* minute,
99                              uint8_t* second,
100                              float32_t* second_fraction);
101 
102 extern int DateTimeCompare(struct date_time* dt1, struct date_time* dt2);
103 
104 extern void TmEncode(struct date_time* dt, struct tm* tm);
105 extern void TmDecode(struct date_time* dt, struct tm* tm);
106 extern void get_current_time(struct date_time* dt);
107 
108 
109 #endif /* BAREOS_LIB_BTIME_H_ */
110