Belle II Software  release-08-01-10
Date.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include "daq/slc/base/Date.h"
9 
10 #include <cstring>
11 
12 using namespace Belle2;
13 
14 Date::Date(time_t time)
15 {
16  set(time);
17 }
18 
19 Date::Date(const Date& date)
20 {
21  set(date.m_time);
22 }
23 
24 Date::Date()
25 {
26  set();
27 }
28 
29 Date::~Date() {}
30 
31 void Date::set()
32 {
33  m_time = time(NULL);
34  m_tm = localtime(&m_time);
35 }
36 
37 void Date::set(time_t time)
38 {
39  m_time = time;
40  m_tm = localtime(&m_time);
41 }
42 
43 int Date::getSecond() const
44 {
45  return m_tm->tm_sec;
46 }
47 
48 int Date::getMinitue() const
49 {
50  return m_tm->tm_min;
51 }
52 
53 int Date::getHour() const
54 {
55  return m_tm->tm_hour;
56 }
57 
58 int Date::getDay() const
59 {
60  return m_tm->tm_mday;
61 }
62 
63 int Date::getMonth() const
64 {
65  return m_tm->tm_mon + 1;
66 }
67 
68 int Date::getYear() const
69 {
70  return m_tm->tm_year + 1900;
71 }
72 
73 const char* Date::toString(const char* format) const
74 {
75  memset(m_str, 0, sizeof(m_str));
76  if (format == NULL) {
77  strftime(m_str, 31, "%Y-%m-%d %H:%M:%S", m_tm);
78  } else {
79  strftime(m_str, 31, format, m_tm);
80  }
81  return m_str;
82 }
Abstract base class for different kinds of events.