1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2007-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
5 +------------------------------------------------------------------------------+
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENCE.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 +-----------------------------------------------------------------------------*/
10 #include <boost/config.hpp>
13 #pragma warning(disable:4996) // This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
16 namespace boost{namespace icl
19 /** Time is a toy-class to demonstrate a class that conforms the requirements of
20 a template parameter for class template icl::interval.
22 In real world applications you may want to use the integer representation of a
23 time variable. That way intervals and their containers are working most efficiently.
26 enum {sunday=0, monday, tuesday, wednesday, thursday, friday, saturday};
27 static const char* daynames[] = {"sun", "mon", "tue", "wed", "thu", "fri", "sat"};
33 Time(int hours, int minutes): m_time(60*hours+minutes) {}
34 Time(int day, int hours, int minutes): m_time((24*60)*day+60*hours+minutes) {}
35 int getDay()const { return m_time/(24*60); }
36 int getHours()const { return (m_time%(24*60))/60; }
37 int getMinutes()const { return (m_time%(24*60))%60; }
38 int asInt()const { return m_time; }
39 std::string getDayString()const { return daynames[getDay()]; }
41 std::string as_string()const
43 const int MAX_TIMESTING_LEN = 256;
44 char repr[MAX_TIMESTING_LEN];
45 sprintf(repr, "%3s:%02d:%02d", getDayString().c_str(), getHours(), getMinutes());
46 return std::string(repr);
49 Time& operator ++ () { m_time++; return *this; }
50 Time& operator -- () { m_time--; return *this; }
57 bool operator < (const Time& x1, const Time& x2) { return x1.asInt() < x2.asInt(); }
58 bool operator == (const Time& x1, const Time& x2) { return x1.asInt() == x2.asInt(); }
59 bool operator <= (const Time& x1, const Time& x2) { return x1.asInt() <= x2.asInt(); }
62 template<class CharType, class CharTraits>
63 std::basic_ostream<CharType, CharTraits> &operator<<
64 (std::basic_ostream<CharType, CharTraits> &stream, Time const& value)
66 return stream << value.as_string();
69 }} // namespace icl boost