MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeModule.cpp
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 as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 
21 #include <ndb_global.h>
22 #include "TimeModule.hpp"
23 
24 static const char* cMonth[] = { "x", "January", "February", "March", "April", "May", "June",
25  "July", "August", "September", "October", "November", "December"};
26 
27 static const char* cDay[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
28  "Saturday", "Sunday"};
29 
30 static const char* cHour[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
31  "13","14","15","16","17","18","19","20","21","22","23"};
32 
33 static const char* cMinute[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
34  "13","14","15","16","17","18","19","20","21","22","23","24","25",
35  "26","27","28","29","30","31","32","33","34","35","36","37","38",
36  "39","40","41","42","43","44","45","46","47","48","49","50","51",
37  "52","53","54","55","56","57","58","59"};
38 
39 static const char* cSecond[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
40  "13","14","15","16","17","18","19","20","21","22","23","24","25",
41  "26","27","28","29","30","31","32","33","34","35","36","37","38",
42  "39","40","41","42","43","44","45","46","47","48","49","50","51",
43  "52","53","54","55","56","57","58","59"};
44 
45 
46 TimeModule::TimeModule(){
47 }
48 
49 TimeModule::~TimeModule(){
50 }
51 
52 void
53 TimeModule::setTimeStamp()
54 {
55  struct tm* rightnow;
56  time_t now;
57 
58  time(&now);
59 
60  rightnow = localtime(&now);
61 
62  iYear = rightnow->tm_year+1900; // localtime returns current year -1900
63  iMonth = rightnow->tm_mon+1; // and month 0-11
64  iMonthDay = rightnow->tm_mday;
65  iWeekDay = rightnow->tm_wday;
66  iHour = rightnow->tm_hour;
67  iMinute = rightnow->tm_min;
68  iSecond = rightnow->tm_sec;
69 }
70 
71 int
72 TimeModule::getYear() const
73 {
74  return iYear;
75 }
76 
77 int
78 TimeModule::getMonthNumber() const
79 {
80  return iMonth;
81 }
82 
83 const char*
84 TimeModule::getMonthName() const {
85  return cMonth[iMonth];
86 }
87 
88 int
89 TimeModule::getDayOfMonth() const {
90  return iMonthDay;
91 }
92 
93 const char*
94 TimeModule::getDayName() const {
95  return cDay[iWeekDay];
96 }
97 
98 const char*
99 TimeModule::getHour() const {
100  return cHour[iHour];
101 }
102 
103 const char*
104 TimeModule::getMinute() const {
105  return cMinute[iMinute];
106 }
107 
108 const char*
109 TimeModule::getSecond() const {
110  return cSecond[iSecond];
111 }