TimeModule.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <ndb_global.h>
  14. #include "TimeModule.hpp"
  15. static const char* cMonth[]  = { "x", "January", "February", "Mars", "April", "May", "June",
  16.  "July", "August", "September", "October", "November", "December"};
  17. static const char* cDay[]    = { "x", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
  18.  "Saturday", "Sunday"};
  19. static const char* cHour[]   = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
  20.  "13","14","15","16","17","18","19","20","21","22","23"};
  21. static const char* cMinute[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
  22.  "13","14","15","16","17","18","19","20","21","22","23","24","25",
  23.  "26","27","28","29","30","31","32","33","34","35","36","37","38",
  24.  "39","40","41","42","43","44","45","46","47","48","49","50","51",
  25.  "52","53","54","55","56","57","58","59"};
  26. static const char* cSecond[] = { "00","01","02","03","04","05","06","07","08","09","10","11","12",
  27.  "13","14","15","16","17","18","19","20","21","22","23","24","25",
  28.  "26","27","28","29","30","31","32","33","34","35","36","37","38",
  29.  "39","40","41","42","43","44","45","46","47","48","49","50","51",
  30.  "52","53","54","55","56","57","58","59"};
  31. TimeModule::TimeModule(){
  32. }
  33. TimeModule::~TimeModule(){
  34. }
  35. void
  36. TimeModule::setTimeStamp()
  37. {
  38.    struct tm* rightnow;
  39.    time_t now;
  40.    time(&now);
  41.    rightnow = localtime(&now);
  42.    iYear     = rightnow->tm_year+1900; // localtime returns current year -1900
  43.    iMonth    = rightnow->tm_mon+1;     // and month 0-11
  44.    iMonthDay = rightnow->tm_mday;
  45.    iWeekDay  = rightnow->tm_wday;
  46.    iHour     = rightnow->tm_hour;
  47.    iMinute   = rightnow->tm_min;
  48.    iSecond   = rightnow->tm_sec;
  49. }
  50. int
  51. TimeModule::getYear() const
  52. {
  53.   return iYear;
  54. }
  55. int
  56. TimeModule::getMonthNumber() const
  57. {
  58.   return iMonth;
  59. }
  60. const char* 
  61. TimeModule::getMonthName() const {
  62.   return cMonth[iMonth];
  63. }
  64. int 
  65. TimeModule::getDayOfMonth() const {
  66.   return iMonthDay;
  67. }
  68. const char* 
  69. TimeModule::getDayName() const {
  70.   return cDay[iWeekDay];
  71. }
  72. const char* 
  73. TimeModule::getHour() const { 
  74.     return cHour[iHour];
  75. }
  76. const char* 
  77. TimeModule::getMinute() const {
  78.   return cMinute[iMinute];
  79. }
  80. const char* 
  81. TimeModule::getSecond() const {
  82.   return cSecond[iSecond];
  83. }