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
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 };
58 
60 class DateTime {
61  time_t value;
62 public:
63  DateTime(time_t t=0);
64  int day() const;
65  int month() const;
66  int year() const;
67  int hour() const;
68  int min() const;
69  int sec() const;
70  time_t timeStamp() const;
71  TimeStruct timeStruct() const;
72  std::string asString(const std::string& format="%u") const;
73 
74  DateTime& setDay(int d);
75  DateTime& setMonth(int m);
76  DateTime& setYear(int y);
77  DateTime& setHour(int d);
78  DateTime& setMin(int m);
79  DateTime& setSec(int y);
80  Date& setTimeStamp(time_t t);
81 };
82 template <>
83 Date convert<const std::string&, Date>(const std::string& value);
84 template <>
85 DateTime convert<const std::string&, DateTime>(const std::string& value);
86 
87 template <>
88 std::string convert<const Date&, std::string>(const Date& value);
89 template <>
90 std::string convert<const DateTime&, std::string>(const DateTime& value);
91 
92 std::ostream& operator << (std::ostream& os, const Date& d);
93 std::ostream& operator << (std::ostream& os, const DateTime& d);
94 }
95 
96 #endif
holds date and time of day
Definition: datetime.hpp:60
holds date
Definition: datetime.hpp:39
Date(time_t t=0)
crops time of day to 00:00:00
Definition: datetime.cpp:62
Definition: datetime.hpp:16
contains FieldType- and Field-classes

SourceForge.net Logo