~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to src/terralib/kernel/TeTimeInterval.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
Import upstream version 3.0.3b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
TerraLib - a library for developing GIS applications.
 
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
 
4
 
 
5
This code is part of the TerraLib library.
 
6
This library is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU Lesser General Public
 
8
License as published by the Free Software Foundation; either
 
9
version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
You should have received a copy of the GNU Lesser General Public
 
12
License along with this library.
 
13
 
 
14
The authors reassure the license terms regarding the warranties.
 
15
They specifically disclaim any warranties, including, but not limited to,
 
16
the implied warranties of merchantability and fitness for a particular purpose.
 
17
The library provided hereunder is on an "as is" basis, and the authors have no
 
18
obligation to provide maintenance, support, updates, enhancements, or modifications.
 
19
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
 
20
indirect, special, incidental, or consequential damages arising out of the use
 
21
of this library and its documentation.
 
22
*************************************************************************************/
 
23
 
 
24
/*! \file TeTimeInterval.h
 
25
    This file contains structures and definitions to deal with date and time intervals
 
26
*/
 
27
 
 
28
#ifndef  __TERRALIB_INTERNAL_TIMEINTERVAL_H
 
29
#define  __TERRALIB_INTERNAL_TIMEINTERVAL_H
 
30
 
 
31
#include <TeTime.h> 
 
32
 
 
33
//! This class provides a set of functions for manipulating date and time intervals
 
34
class TeTimeInterval
 
35
{
 
36
private:
 
37
 
 
38
        TeTime  t1_;
 
39
        TeTime  t2_;
 
40
        TeChronon  intChronon_;
 
41
 
 
42
        void adjustIntervaltoChronon ();
 
43
 
 
44
public:
 
45
        
 
46
        //!     Set the date and time from the system clock
 
47
        void now(void) {t1_.now(); t2_.now();}
 
48
 
 
49
        //! Empty constructor
 
50
        TeTimeInterval (void):  t1_(), t2_() {}
 
51
 
 
52
        //!     Set all time information from the system clock
 
53
        TeTimeInterval (TeTime& t1, TeTime& t2):        t1_(t1), t2_(t2) {}
 
54
 
 
55
        //!     Copy constructor.
 
56
        TeTimeInterval(const TeTimeInterval& t): t1_(t.t1_), t2_(t.t2_) {}
 
57
 
 
58
        //!     Set date and time from arguments, though the time fields defaults to zero.
 
59
        TeTimeInterval(const string& t1, const string& t2, TeChronon chronon=TeSECOND, const string& mask="YYYYsMMsDDsHHsmmsSS", const string& dateS = "/", const string& timeS = ":", const string& indPM = "PM");
 
60
 
 
61
        //!     Set date and time from arguments, though the time fields defaults to zero.
 
62
        TeTimeInterval(const string& t1, TeChronon chronon=TeSECOND, const string& mask="YYYYsMMsDDsHHsmmsSS", int delta = 0, int numsteps = 1): 
 
63
                t1_ (t1,  chronon, mask)
 
64
        {
 
65
                t2_ = t1_ + (delta-1)*numsteps; 
 
66
                adjustIntervaltoChronon();
 
67
        }
 
68
 
 
69
        //! Returns the chronon of the interval
 
70
        TeChronon intervalChronon() { return  intChronon_; }
 
71
 
 
72
        //! Sets the chronon of the interval
 
73
        void intervalChronon(TeChronon c);  
 
74
 
 
75
        //!     Return a time of day string in format "hh:mm:ss"
 
76
        string getInitialTime()                 {return t1_.getTime();}
 
77
 
 
78
        //!     Return a time of day string in format "hh:mm:ss"
 
79
        string getFinalTime()                   {return t2_.getTime();}
 
80
 
 
81
        //!     Return a string to the date in the form "yyyy-mm-dd"
 
82
        string getInitialDate(void)             {return t1_.getDate();}
 
83
 
 
84
        //!     Return a string to the date in the form "yyyy-mm-dd"
 
85
        string getFinalDate(void)               {return t2_.getDate();}
 
86
 
 
87
        //! Return the time t1_
 
88
        TeTime& getT1 (void) {return t1_;}
 
89
 
 
90
        //! Return the time t2_
 
91
        TeTime& getT2 (void) {return t2_;}
 
92
 
 
93
        //!     Return a pointer to the date and time in the form passed in mask.  
 
94
        string getInitialDateTime (const string& mask="YYYYsMMsDDsHHsmmsSS", const string& dateS="/", const string& timeS=":", const string& indPM="PM", const string& indAM="AM") {return t1_.getDateTime(mask, dateS, timeS, indPM, indAM);}
 
95
 
 
96
        //!     Return a pointer to the date and time in the form passed in mask.  
 
97
        string getFinalDateTime (const string& mask="YYYYsMMsDDsHHsmmsSS", const string& dateS="/", const string& timeS=":", const string& indPM="PM", const string& indAM="AM") {return t2_.getDateTime(mask, dateS, timeS, indPM, indAM);}
 
98
 
 
99
        
 
100
        //! Reset time to the specified arguments. Return time_t: number of seconds since 0:00:00 Jan 1 1987
 
101
        /*!
 
102
      \param y  year
 
103
          \param m  month
 
104
          \param d  day
 
105
          \param h  hour
 
106
          \param min  minutes
 
107
      \param s  seconds
 
108
        */
 
109
        time_t setInitialTime (int y, int m, int d, int h = 0, int min = 0, int s = 0)
 
110
        {return t1_.Set(y, m, d, h, min, s);}
 
111
 
 
112
 
 
113
        //! Reset time to the specified arguments. Return time_t: number of seconds since 0:00:00 Jan 1 1987
 
114
        /*!
 
115
      \param y  year
 
116
          \param m  month
 
117
          \param d  day
 
118
          \param h  hour
 
119
          \param min  minutes
 
120
      \param s  seconds
 
121
        */
 
122
        time_t setFinalTime (int y, int m, int d, int h = 0, int min = 0, int s = 0) 
 
123
        {return t2_.Set(y, m, d, h, min, s);}
 
124
 
 
125
        //!     Assignment operator for TeTime objects.
 
126
        TeTimeInterval& operator=(const TeTimeInterval& t) {t1_ = t.t1_;  t2_ = t.t2_; intChronon_ = t.intChronon_; return (*this);}
 
127
 
 
128
        //! Operator ==
 
129
        bool operator==(const TeTimeInterval& other) const { return (this->t1_ == other.t1_ && this->t2_ == other.t2_); } 
 
130
 
 
131
        //! Compute legnth of time interval in units of chonon
 
132
        int length ();
 
133
 
 
134
        //! Shift the interval, begining at time t (in the form "yyyy-mm-dd hh:mm:ss").
 
135
        /*!
 
136
                If t is not provided, the current final time becomes the initial time. 
 
137
                The interval length is maintained.
 
138
        */
 
139
        void shift (const string& t = "");
 
140
 
 
141
        
 
142
        //! Shift the interval, begining delta units after the initial time. The interval length is maintained.
 
143
        void shiftPlus (int delta);
 
144
 
 
145
        //! Shift the interval, begining delta units before the initial time. The interval length is maintained.
 
146
        void shiftMinus (int delta);
 
147
 
 
148
        //! verify if the times have null values
 
149
        bool isValid() { return (t1_.isValid() || t2_.isValid()); } 
 
150
        
 
151
    //! Normal destructor.
 
152
        ~TeTimeInterval(void) { }
 
153
 
 
154
        //! verify if a specific time is during the interval time
 
155
        bool  during (TeTime& time);
 
156
 
 
157
        //! verify if a specific time is before the interval time
 
158
        bool  before (TeTime& time);
 
159
 
 
160
 
 
161
};
 
162
ostream& operator<<(ostream& os, TeTime& N);
 
163
 
 
164
#endif
 
165
 
 
166