LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
DateTime.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_DAF_BASE_DATETIME_H
26 #define LSST_DAF_BASE_DATETIME_H
27 
44 #include <ctime>
45 #include <sys/time.h>
46 #include <string>
47 
48 // Forward declaration of the boost::serialization::access class.
49 namespace boost {
50 namespace serialization {
51  class access;
52 }} // namespace boost::serialization
53 
54 namespace lsst {
55 namespace daf {
56 namespace base {
57 
58 class DateTime {
59 public:
60  enum Timescale { TAI, UTC, TT };
61  enum DateSystem { JD, MJD, EPOCH };
62  explicit DateTime(long long nsecs = 0LL, Timescale scale = TAI);
63  explicit DateTime(double date, DateSystem system = MJD, Timescale scale = TAI);
64  DateTime(int year, int month, int day, int hr, int min, int sec,
65  Timescale scale = TAI);
66  explicit DateTime(std::string const& iso8601, Timescale scale);
67 
68  long long nsecs(Timescale scale = TAI) const;
69  double get(DateSystem system = MJD, Timescale scale = TAI) const;
70  std::string toString(Timescale scale) const;
71 
72  struct tm gmtime(Timescale time) const;
73  struct timespec timespec(Timescale time) const;
74  struct timeval timeval(Timescale time) const;
75 
76  bool operator==(DateTime const& rhs) const;
77 
78  static DateTime now(void);
79 
80  static void initializeLeapSeconds(std::string const& leapString);
81 
82 private:
83  long long _nsecs;
84 
85  double _getMjd(Timescale scale) const;
86  double _getJd(Timescale scale) const;
87  double _getEpoch(Timescale scale) const;
88 
89  void setNsecsFromMjd(double mjd, Timescale scale);
90  void setNsecsFromJd(double jd, Timescale scale);
91  void setNsecsFromEpoch(double epoch, Timescale scale);
92 
98  template <class Archive> void serialize(Archive ar, int const version) {
99  ar & _nsecs;
100  }
101 
102 };
103 
104 }}} // namespace lsst::daf::base
105 
106 #endif
static DateTime now(void)
Definition: DateTime.cc:601
double _getEpoch(Timescale scale) const
Definition: DateTime.cc:524
void setNsecsFromEpoch(double epoch, Timescale scale)
a function to convert epoch to internal nsecs
Definition: DateTime.cc:313
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
double _getJd(Timescale scale) const
Definition: DateTime.cc:516
bool operator==(DateTime const &rhs) const
Definition: DateTime.cc:592
void setNsecsFromJd(double jd, Timescale scale)
a function to convert JD to internal nsecs
Definition: DateTime.cc:304
void serialize(Archive ar, int const version)
Definition: DateTime.h:98
void setNsecsFromMjd(double mjd, Timescale scale)
a function to convert MJD to integral nsecs
Definition: DateTime.cc:284
static void initializeLeapSeconds(std::string const &leapString)
Definition: DateTime.cc:615
long long nsecs(Timescale scale=TAI) const
Definition: DateTime.cc:496
struct tm gmtime(Timescale time) const
Definition: DateTime.cc:534
struct timeval timeval(Timescale time) const
Definition: DateTime.cc:564
long long _nsecs
Nanoseconds since Unix epoch.
Definition: DateTime.h:83
double _getMjd(Timescale scale) const
Definition: DateTime.cc:505
friend class boost::serialization::access
Definition: DateTime.h:93
DateTime(long long nsecs=0LL, Timescale scale=TAI)
Definition: DateTime.cc:323
struct timespec timespec(Timescale time) const
Definition: DateTime.cc:553
std::string toString(Timescale scale) const
Definition: DateTime.cc:575