CARMA C++
Time.h
1 // $Id: Time.h,v 1.1 2010/12/13 21:06:33 eml Exp $
2 
3 #ifndef SZA_UTIL_TIME_H
4 #define SZA_UTIL_TIME_H
5 
15 #include "carma/szautil/ConformableQuantity.h"
16 
17 namespace sza {
18  namespace util {
19 
20  class Time : public ConformableQuantity {
21  public:
22 
23  class Seconds {};
24  class NanoSeconds {};
25 
26  // Scale factors used by this class
27 
28  static const double nsPerSecond_;
29  static const double secPerMinute_;
30  static const double secPerHour_;
31  static const double secPerDay_;
32  static const double dayPerYear_;
33 
37  Time();
38  Time(const Time& time);
39  Time(const Seconds& units, double s);
40  Time(const NanoSeconds& units, double ns);
41 
45  virtual ~Time();
46 
47  // Set the time of this object
48 
49  void setSeconds(double s)
50  {
51  s_ = s;
52  }
53 
54  void setNanoSeconds(double ns)
55  {
56  s_ = ns / nsPerSecond_;
57  }
58 
59  inline double years() const {
60  return s_ / (secPerDay_ * dayPerYear_);
61  }
62 
63  inline double days() const {
64  return s_ / secPerDay_;
65  }
66 
67  inline double hours() const {
68  return s_ / secPerHour_;
69  }
70 
71  inline double minutes() const {
72  return s_ / secPerMinute_;
73  }
74 
75  inline double seconds() const {
76  return s_;
77  }
78 
79  inline double nanoSeconds() const {
80  return s_ * nsPerSecond_;
81  }
82 
83  void initialize();
84 
85  friend std::ostream& operator<<(std::ostream& os, Time& time);
86 
87  private:
88 
89  double s_;
90 
91  }; // End class Time
92 
93  std::ostream& operator<<(std::ostream& os, Time& time);
94 
95  } // End namespace util
96 } // End namespace sza
97 
98 
99 
100 #endif // End #ifndef SZA_UTIL_TIME_H