1
/************************************************************************************
2
TerraLib - a library for developing GIS applications.
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
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.
11
You should have received a copy of the GNU Lesser General Public
12
License along with this library.
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
*************************************************************************************/
24
/*! \file TeTimeInterval.h
25
This file contains structures and definitions to deal with date and time intervals
28
#ifndef __TERRALIB_INTERNAL_TIMEINTERVAL_H
29
#define __TERRALIB_INTERNAL_TIMEINTERVAL_H
33
//! This class provides a set of functions for manipulating date and time intervals
40
TeChronon intChronon_;
42
void adjustIntervaltoChronon ();
46
//! Set the date and time from the system clock
47
void now(void) {t1_.now(); t2_.now();}
50
TeTimeInterval (void): t1_(), t2_() {}
52
//! Set all time information from the system clock
53
TeTimeInterval (TeTime& t1, TeTime& t2): t1_(t1), t2_(t2) {}
56
TeTimeInterval(const TeTimeInterval& t): t1_(t.t1_), t2_(t.t2_) {}
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");
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)
65
t2_ = t1_ + (delta-1)*numsteps;
66
adjustIntervaltoChronon();
69
//! Returns the chronon of the interval
70
TeChronon intervalChronon() { return intChronon_; }
72
//! Sets the chronon of the interval
73
void intervalChronon(TeChronon c);
75
//! Return a time of day string in format "hh:mm:ss"
76
string getInitialTime() {return t1_.getTime();}
78
//! Return a time of day string in format "hh:mm:ss"
79
string getFinalTime() {return t2_.getTime();}
81
//! Return a string to the date in the form "yyyy-mm-dd"
82
string getInitialDate(void) {return t1_.getDate();}
84
//! Return a string to the date in the form "yyyy-mm-dd"
85
string getFinalDate(void) {return t2_.getDate();}
87
//! Return the time t1_
88
TeTime& getT1 (void) {return t1_;}
90
//! Return the time t2_
91
TeTime& getT2 (void) {return t2_;}
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);}
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);}
100
//! Reset time to the specified arguments. Return time_t: number of seconds since 0:00:00 Jan 1 1987
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);}
113
//! Reset time to the specified arguments. Return time_t: number of seconds since 0:00:00 Jan 1 1987
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);}
125
//! Assignment operator for TeTime objects.
126
TeTimeInterval& operator=(const TeTimeInterval& t) {t1_ = t.t1_; t2_ = t.t2_; intChronon_ = t.intChronon_; return (*this);}
129
bool operator==(const TeTimeInterval& other) const { return (this->t1_ == other.t1_ && this->t2_ == other.t2_); }
131
//! Compute legnth of time interval in units of chonon
134
//! Shift the interval, begining at time t (in the form "yyyy-mm-dd hh:mm:ss").
136
If t is not provided, the current final time becomes the initial time.
137
The interval length is maintained.
139
void shift (const string& t = "");
142
//! Shift the interval, begining delta units after the initial time. The interval length is maintained.
143
void shiftPlus (int delta);
145
//! Shift the interval, begining delta units before the initial time. The interval length is maintained.
146
void shiftMinus (int delta);
148
//! verify if the times have null values
149
bool isValid() { return (t1_.isValid() || t2_.isValid()); }
151
//! Normal destructor.
152
~TeTimeInterval(void) { }
154
//! verify if a specific time is during the interval time
155
bool during (TeTime& time);
157
//! verify if a specific time is before the interval time
158
bool before (TeTime& time);
162
ostream& operator<<(ostream& os, TeTime& N);