libi2ncommon: (gerd) add time output functions
[libi2ncommon] / src / timefunc.hxx
1 /***************************************************************************
2                           timecvt.hxx  -  description
3                              -------------------
4     begin                : Fri May 11 2001
5     copyright            : (C) 2001 by STYLETEC
6     email                : info@styletec.de
7  ***************************************************************************/
8
9 #ifndef __TIMEFUNC_HXX
10 #define __TIMEFUNC_HXX
11
12 #include <bitset>
13
14 double prec_time(void);
15
16 int date_to_seconds(const std::string &date);
17
18 std::string make_nice_time(int seconds);
19 std::string format_full_time(int seconds);
20 void seconds_to_hour_minute(int seconds, int *hour, int *minute);
21 std::string output_hour_minute(int hour, int minute);
22
23 inline std::string output_hour_minute_from_seconds(int seconds)
24 {
25     int hour, minute;
26     seconds_to_hour_minute(seconds,&hour,&minute);
27     return output_hour_minute(hour,minute);
28 }
29
30 class WEEK
31 {
32     private:
33         std::bitset<7> days;
34
35     public:
36         enum WEEKDAY { SU=0, MO=1, TU=2, WE=3, TH=4, FR=5, SA=6 };
37         
38         // throws out_of_range if illegal week
39         WEEK(const std::string& daystring);
40         
41         WEEK(const std::bitset<7> &days)
42             : days(days)
43             { }
44             
45         WEEK()
46             { }
47             
48         void clear()
49             { days.reset(); }
50             
51         operator std::bitset<7>() const
52             { return days; }
53         
54         std::string get_daystring() const;
55         std::string get_displaystring() const;
56         std::string get_netfilterstring() const;
57         
58         static std::string get_day_display(WEEKDAY day);
59         static std::string get_english_display(WEEKDAY day);
60 };
61
62 #endif