1 /***************************************************************************
2 timecvt.cpp - description
4 begin : Fri May 11 2001
5 copyright : (C) 2001 by STYLETEC
6 email : info@styletec.de
7 ***************************************************************************/
17 #include <sys/timeb.h>
19 #include <timefunc.hxx>
24 double prec_time(void)
31 ret=tb.time+(static_cast<float>(tb.millitm)/1000);
36 // converts ISO-DATE: 2003-06-13
37 int date_to_seconds(const std::string &date)
39 int rtn = -1, year = -1, month = -1, day = -1;
41 string::size_type pos = date.find("-");
42 if (pos == string::npos)
45 istringstream in(string(date,0,pos));
49 string dstr(date, pos+1);
50 if ((pos = dstr.find("-")) == string::npos)
54 in.str(string(dstr, 0, pos));
59 in.str(string(dstr, pos+1));
62 if (year < 0 || month == -1 || day == -1)
66 bzero (&tm_struct, sizeof(struct tm));
67 tm_struct.tm_year = year;
68 tm_struct.tm_mon = month;
69 tm_struct.tm_mday = day;
70 tm_struct.tm_isdst = -1;
72 rtn = mktime (&tm_struct);
76 string make_nice_time(int seconds)
80 int days=seconds/86400;
83 int hours=seconds/3600;
86 int minutes=seconds/60;
90 out << i18n("1 day") << ", ";
92 out << days << ' ' << i18n("days") << ", ";
95 out << setw(2) << hours << ':' << setw(2) << minutes << ':' << setw(2) << seconds;
100 string format_full_time(int seconds)
104 struct tm *ta = localtime ((time_t *)&seconds);
106 strftime (buf, 49, "%d.%m.%Y %H:%M", ta);
110 WEEK::WEEK(const std::string& daystring)
112 int len=daystring.length();
113 for (int p=0; p < len; p++)
115 char nr=daystring[p];
116 istringstream c(&nr);
118 if (!(c >> wnr) || wnr<0 || wnr >6)
119 throw out_of_range("illegal weekday in "+daystring);
125 std::string WEEK::get_daystring() const
128 for (int i = 0; i < 7; i++)
135 std::string WEEK::get_displaystring() const
139 // From Monday to Saturday
141 for (int i = 1; i < 7; i++)
145 if (!weekdays_str.empty())
146 weekdays_str += ", ";
148 weekdays_str += get_day_display(static_cast<WEEKDAY>(i));
150 // check if we can group two or more days
152 while (days[j] && j < 7)
156 // Sunday end of week? j -> 7
157 if (j-i > 0 && j == 6 && days[0])
163 weekdays_str += "-" + get_day_display(SU);
165 weekdays_str += "-" + get_day_display(static_cast<WEEKDAY>(j));
173 if (days[0] && j != 7)
175 if (!weekdays_str.empty())
176 weekdays_str += ", ";
178 weekdays_str += get_day_display(SU);
184 std::string WEEK::get_netfilterstring() const
187 for (int i = 0; i < 7; i++)
192 out+=get_english_display(static_cast<WEEKDAY>(i));;
198 std::string WEEK::get_day_display(WEEKDAY day)
204 weekday_str = i18n("Mon");
207 weekday_str = i18n("Tue");
210 weekday_str = i18n("Wed");
213 weekday_str = i18n("Thu");
216 weekday_str = i18n("Fri");
219 weekday_str = i18n("Sat");
222 weekday_str = i18n("Sun");
231 std::string WEEK::get_english_display(WEEKDAY day)