LiteSQL
datetime.hpp
Go to the documentation of this file.
1 /* LiteSQL
2  *
3  * The list of contributors at http://litesql.sf.net/
4  *
5  * See LICENSE for copyright information. */
6 
7 #ifndef litesql_datetime_hpp
8 #define litesql_datetime_hpp
9 
11 #include "field.hpp"
12 #include <ctime>
13 namespace litesql {
14 
15 /* holds struct tm */
16 class TimeStruct {
17  struct tm mytm;
18 public:
19  TimeStruct(time_t t=0);
20  int day() const;
21  int dayOfWeek() const;
22  int dayOfYear() const;
23  int month() const;
24  int year() const;
25  int hour() const;
26  int min() const;
27  int sec() const;
28  time_t timeStamp() const;
29  TimeStruct& setDay(int day);
30  TimeStruct& setMonth(int month);
31  TimeStruct& setYear(int year);
32  TimeStruct& setHour(int hour);
33  TimeStruct& setMin(int min);
34  TimeStruct& setSec(int sec);
35  TimeStruct& setTimeStamp(time_t t);
36 };
37 
39 class Date {
40  time_t value;
41 public:
43  Date(time_t t=0);
44  Date(int day, int month, int year);
45  int day() const;
46  int dayOfWeek() const;
47  int month() const;
48  int year() const;
49  time_t timeStamp() const;
50  TimeStruct timeStruct() const;
51 
52  Date& setDay(int d);
53  Date& setMonth(int m);
54  Date& setYear(int y);
55  Date& setTimeStamp(time_t t);
56  std::string asString(const std::string& format="%u") const;
57 };
59 class Time {
61  int value;
62 public:
63  Time(int secs=0);
64  Time(int hour, int min, int sec);
65  int hour() const;
66  int min() const;
67  int sec() const;
68  int secs() const;
69  std::string asString(const std::string& format="%u") const;
70 
71  Time& setHour(int d);
72  Time& setMin(int m);
73  Time& setSec(int y);
74  Time& setSecs(int secs);
75 };
77 class DateTime {
78  time_t value;
79 public:
80  DateTime(time_t t=0);
81  int day() const;
82  int month() const;
83  int year() const;
84  int hour() const;
85  int min() const;
86  int sec() const;
87  time_t timeStamp() const;
88  TimeStruct timeStruct() const;
89  std::string asString(const std::string& format="%u") const;
90 
91  DateTime& setDay(int d);
92  DateTime& setMonth(int m);
93  DateTime& setYear(int y);
94  DateTime& setHour(int d);
95  DateTime& setMin(int m);
96  DateTime& setSec(int y);
97  Date& setTimeStamp(time_t t);
98 };
99 template <>
100 Date convert<const std::string&, Date>(const std::string& value);
101 template <>
102 Time convert<const std::string&, Time>(const std::string& value);
103 template <>
104 DateTime convert<const std::string&, DateTime>(const std::string& value);
105 
106 template <>
107 std::string convert<const Date&, std::string>(const Date& value);
108 template <>
109 std::string convert<const Time&, std::string>(const Time& value);
110 template <>
111 std::string convert<const DateTime&, std::string>(const DateTime& value);
112 
113 std::ostream& operator << (std::ostream& os, const Date& d);
114 std::ostream& operator << (std::ostream& os, const Time& d);
115 std::ostream& operator << (std::ostream& os, const DateTime& d);
116 }
117 
118 #endif
litesql::Date
holds date
Definition: datetime.hpp:39
litesql::toString
std::string toString(T a)
returns string representation of passed parameter if it can be written to ostringstream
Definition: string.hpp:20
datetime.hpp
litesql::DateTime
holds date and time of day
Definition: datetime.hpp:77
litesql::split
std::vector< std::string > split(const std::string &s, const std::string &delim=" ")
from string.
litesql::Date::Date
Date(time_t t=0)
crops time of day to 00:00:00
Definition: datetime.cpp:79
litesql::atoi
int atoi(const std::string &s)
string version of atoi
field.hpp
litesql::Time
holds time of day
Definition: datetime.hpp:59
litesql::TimeStruct
Definition: datetime.hpp:16

SourceForge.net Logo