1 /*
2 Copyright (C) 2003-2007 MySQL AB
3 All rights reserved. Use is subject to license terms.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26
27
28 #include <ndb_global.h>
29 #include "TimeModule.hpp"
30
31 static const char* cMonth[] = { "x", "January", "February", "March", "April", "May", "June",
32 "July", "August", "September", "October", "November", "December"};
33
34 static const char* cDay[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
35 "Saturday", "Sunday"};
36
37 static const char* cHour[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
38 "13","14","15","16","17","18","19","20","21","22","23"};
39
40 static const char* cMinute[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
41 "13","14","15","16","17","18","19","20","21","22","23","24","25",
42 "26","27","28","29","30","31","32","33","34","35","36","37","38",
43 "39","40","41","42","43","44","45","46","47","48","49","50","51",
44 "52","53","54","55","56","57","58","59"};
45
46 static const char* cSecond[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
47 "13","14","15","16","17","18","19","20","21","22","23","24","25",
48 "26","27","28","29","30","31","32","33","34","35","36","37","38",
49 "39","40","41","42","43","44","45","46","47","48","49","50","51",
50 "52","53","54","55","56","57","58","59"};
51
52
TimeModule()53 TimeModule::TimeModule(){
54 }
55
~TimeModule()56 TimeModule::~TimeModule(){
57 }
58
59 void
setTimeStamp()60 TimeModule::setTimeStamp()
61 {
62 struct tm* rightnow;
63 time_t now;
64
65 time(&now);
66
67 rightnow = localtime(&now);
68
69 iYear = rightnow->tm_year+1900; // localtime returns current year -1900
70 iMonth = rightnow->tm_mon+1; // and month 0-11
71 iMonthDay = rightnow->tm_mday;
72 iWeekDay = rightnow->tm_wday;
73 iHour = rightnow->tm_hour;
74 iMinute = rightnow->tm_min;
75 iSecond = rightnow->tm_sec;
76 }
77
78 int
getYear() const79 TimeModule::getYear() const
80 {
81 return iYear;
82 }
83
84 int
getMonthNumber() const85 TimeModule::getMonthNumber() const
86 {
87 return iMonth;
88 }
89
90 const char*
getMonthName() const91 TimeModule::getMonthName() const {
92 return cMonth[iMonth];
93 }
94
95 int
getDayOfMonth() const96 TimeModule::getDayOfMonth() const {
97 return iMonthDay;
98 }
99
100 const char*
getDayName() const101 TimeModule::getDayName() const {
102 return cDay[iWeekDay];
103 }
104
105 const char*
getHour() const106 TimeModule::getHour() const {
107 return cHour[iHour];
108 }
109
110 const char*
getMinute() const111 TimeModule::getMinute() const {
112 return cMinute[iMinute];
113 }
114
115 const char*
getSecond() const116 TimeModule::getSecond() const {
117 return cSecond[iSecond];
118 }
119