PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Types | Private Member Functions
PLearn::Calendar Class Reference

Encapsulates the concept of a calendar as an ordered finite list of timestamps. More...

#include <Calendar.h>

Inheritance diagram for PLearn::Calendar:
Inheritance graph
[legend]
Collaboration diagram for PLearn::Calendar:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Calendar ()
 Default constructor.
 Calendar (const JTimeVec &timestamps)
 Constructor with specified timestamps (julian dates)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual CalendardeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
bool isEmpty () const
 Returns true iff this calendar contains no timestamps.
const JTimeVecgetTimeStamps () const
 Returns a reference to the timestamps.
bool operator== (const Calendar &cal)
 Returns true iff the calendar have the exact same timestamps.
bool operator!= (const Calendar &cal)
 Returns true iff the calendar has different timestamps.
int size () const
 Returns the number of timestamps.
JTime getTime (CTime calendar_time) const
 Returns timestamp corresponding to "calendar_time".
JTime operator[] (CTime calendar_time) const
CTime getCalendarTime (JTime julian_time, bool use_lower_bound=true) const
 Returns the calendar time corresponding to julian time "julian_time".
CTime getLastDayOfMonth (const PDate &day_of_the_month) const
 Given a PDate D, returns the last calendar day in the same month than D.
bool containsTime (JTime julian_time, CTime *calendar_time=0) const
 Returns true iff julian_time is a valid timestamp.
JTime calendarTimeOnOrAfter (JTime julian_time) const
 Return the JTime of the day in the calendar that comes ON OR AFTER the specified day, or MAX_TIME if no such day exist.
JTime calendarTimeOnOrBefore (JTime julian_time) const
 Return the JTime of the day in the calendar that comes ON OR BEFORE the specified day, or MIN_TIME if no such day exist.
PCalendar clamp (JTime lower, JTime upper)
 Return the subset of dates of this calendar that that are between the given lower and upper times (both endpoints are included in the the subset).
void setResampling (Calendar *other_cal, const TVec< int > &resampling)
 Associate or modify a resampling to another calendar.
TVec< intgetResampling (Calendar *other_cal)
 Return the resampling to another calendar or an empty vector if it does not exist.
void remote_setGlobalCalendar (string calendar_name, Vec calendar_dates)
JTimeVec remote_getGlobalCalendar (string calendar_name)

Static Public Member Functions

static PCalendar makeCalendar (const Vec &dates)
 This returns a calendar from a vector of "dates".
static string _classname_ ()
static OptionList_getOptionList_ ()
static RemoteMethodMap_getRemoteMethodMap_ ()
static Object_new_instance_for_typemap_ ()
static bool _isa_ (const Object *o)
static void _static_initialize_ ()
static const PPathdeclaringFile ()
static CTime convertCalendarTime (const Calendar &source_calendar, const Calendar &dest_calendar, CTime source_time, bool use_lower_bound=true)
 Converts a calendar.
static PCalendar unite (const TVec< PCalendar > &calendars)
 Return the union of a set of calendars.
static PCalendar intersect (const TVec< PCalendar > &calendars)
 Return the intersection of a set of calendars.
static PCalendar calendarDiff (const Calendar *cal, const JTimeVec &to_remove)
 Return a new calendar containing the dates of a starting calendar MINUS the dates given in the list.
static void setGlobalCalendar (const string &calendar_name, PCalendar calendar)
 Set a global calendar keyed to the given string.
static const CalendargetGlobalCalendar (const string &calendar_name)
 Return a pointer to the global calendar given the string.

Public Attributes

JTimeVec timestamps_
 The list of julian timestamps that define this calendar.
Vec dwim_timestamps_
 Alternative list of "human timestamps" that may be provided in any of the following formats: Julian, CYYMMDD, YYYYMMDD.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.
static void declareMethods (RemoteMethodMap &rmm)
 Declare the methods that are remote-callable.

Protected Attributes

JTime last_julian_time_
 Input value to last call to getCalendarTime.
CTime last_calendar_time_
 Value returned by last call to getCalendarTime.
bool last_use_lower_bound
 Last argument used when calling getCalendarTime.
map< Calendar *, TVec< int > > active_resamplings
 Internal map containing memoized resamplings for the calendar.

Static Protected Attributes

static map< string, PP
< Calendar > > 
global_calendars
 The set of currently-installed global calendars.

Private Types

typedef Object inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Encapsulates the concept of a calendar as an ordered finite list of timestamps.

This class encapsulates the concept of a calendar as an ordered finite list of timestamps. The idea is to provide a tool to convert a continuous representation of time (as julian dates) into a discrete one. Not only the calendar time units (CTime) are different, but the time axis may "leap-over" time ranges in the continous time (JTime) axis.

For instance, one may want to represent a conception of time where time is sampled daily but only during business week days (i.e. monday to friday) s.t. when time t is a friday, time (t+1) will be the next monday (and not saturday). Such a calendar would contain, in its internal representation, a list of timestamps that correspond to, say, Midnight of every Mon/Tues/Wednes/Thurs/Fri-days from, say, 1900 to 2099.

In addition, the class supports a set of global (static) calendars keyed by a string. Functions are provided to set/get global calendars associated with string keys. A Remote-Method interface is provided as well to set global calendars. Special operators are available in VMatLanguage to access those global calendars.

Definition at line 122 of file Calendar.h.


Member Typedef Documentation

Reimplemented from PLearn::Object.

Definition at line 125 of file Calendar.h.


Constructor & Destructor Documentation

PLearn::Calendar::Calendar ( )

Default constructor.

Definition at line 83 of file Calendar.cc.

Referenced by calendarDiff(), clamp(), intersect(), makeCalendar(), and unite().

Here is the caller graph for this function:

PLearn::Calendar::Calendar ( const JTimeVec timestamps)

Constructor with specified timestamps (julian dates)

Definition at line 91 of file Calendar.cc.

References build_().

Here is the call graph for this function:


Member Function Documentation

string PLearn::Calendar::_classname_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

OptionList & PLearn::Calendar::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

RemoteMethodMap & PLearn::Calendar::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

bool PLearn::Calendar::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

Object * PLearn::Calendar::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

StaticInitializer Calendar::_static_initializer_ & PLearn::Calendar::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

void PLearn::Calendar::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::Object.

Definition at line 216 of file Calendar.cc.

References PLearn::Object::build(), and build_().

Here is the call graph for this function:

void PLearn::Calendar::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 141 of file Calendar.cc.

References dwim_timestamps_, PLearn::fast_exact_is_equal(), i, PLearn::TVec< T >::length(), makeCalendar(), PLWARNING, PLearn::TVec< T >::size(), and timestamps_.

Referenced by build(), and Calendar().

{
    // If we have dwim_timestamps_ and no timestamps_, fill latter from former
    if (dwim_timestamps_.size() > 0 && timestamps_.size() == 0) {
        PCalendar cal = makeCalendar(dwim_timestamps_);
        timestamps_ = cal->timestamps_;
    }

    // perform some preventive checks
    bool doublons = false;
    bool disordered = false;
    for (int i=1; i<timestamps_.length(); i++)
    {
        if (fast_exact_is_equal(timestamps_[i], timestamps_[i-1]))
        {
            doublons = true;
            if (disordered) break;
        }
        else if (timestamps_[i] < timestamps_[i-1])
        {
            disordered = true;
            if (doublons) break;
        }
    }
    if (doublons)
        PLWARNING("In Calendar::build_(), provided timestamps contained repetitions.\n"
                  "The calendar's behavior is therefore undefined. Please check it.");
    if (disordered)
        PLWARNING("In Calendar::build_(), provided timestamps were disordered.\n"
                  "The calendar's behavior is therefore undefined. Please check it.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

PCalendar PLearn::Calendar::calendarDiff ( const Calendar cal,
const JTimeVec to_remove 
) [static]

Return a new calendar containing the dates of a starting calendar MINUS the dates given in the list.

Definition at line 380 of file Calendar.cc.

References PLearn::TVec< T >::begin(), Calendar(), std::copy(), PLearn::TVec< T >::end(), i, n, PLearn::TVec< T >::size(), and timestamps_.

{
    set<JTime> cal_times(cal->timestamps_.begin(), cal->timestamps_.end());
    for (int i=0, n=to_remove.size() ; i<n ; ++i)
        cal_times.erase(to_remove[i]);

    JTimeVec new_timestamps(int(cal_times.size()));
    copy(cal_times.begin(), cal_times.end(), new_timestamps.begin());
    return new Calendar(new_timestamps);
}

Here is the call graph for this function:

JTime PLearn::Calendar::calendarTimeOnOrAfter ( JTime  julian_time) const

Return the JTime of the day in the calendar that comes ON OR AFTER the specified day, or MAX_TIME if no such day exist.

Definition at line 295 of file Calendar.cc.

References getCalendarTime(), getTime(), and PLearn::MAX_TIME.

Referenced by PLearn::VMatLanguage::run().

{
    CTime start_point = getCalendarTime(julian_time);
    if (getTime(start_point) < julian_time)    // if at very end of calendar
        return MAX_TIME;
    else
        return getTime(start_point);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JTime PLearn::Calendar::calendarTimeOnOrBefore ( JTime  julian_time) const

Return the JTime of the day in the calendar that comes ON OR BEFORE the specified day, or MIN_TIME if no such day exist.

Definition at line 305 of file Calendar.cc.

References getCalendarTime(), getTime(), and PLearn::MIN_TIME.

Referenced by PLearn::VMatLanguage::run().

{
    CTime start_point = getCalendarTime(julian_time);
    while (start_point >= 0 && getTime(start_point) > julian_time)
        start_point--;
    if (start_point < 0)
        return MIN_TIME;
    else
        return getTime(start_point);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PCalendar PLearn::Calendar::clamp ( JTime  lower,
JTime  upper 
)

Return the subset of dates of this calendar that that are between the given lower and upper times (both endpoints are included in the the subset).

Warning: a subVec into the original timestamps is returned -- a full copy of the vector is not made.

Definition at line 392 of file Calendar.cc.

References Calendar(), getCalendarTime(), PLASSERT, size(), PLearn::TVec< T >::subVec(), and timestamps_.

{
    // Handle degenerate cases
    if (size() == 0 || upper < (*this)[0] || lower > (*this)[size()-1])
        return new Calendar;
    
    CTime lower_ctime = getCalendarTime(lower, /* use_lower_bound= */ true);
    CTime upper_ctime = getCalendarTime(upper, /* use_lower_bound= */ false);
    if ((*this)[upper_ctime] > upper)
        --upper_ctime;
    PLASSERT( lower_ctime <= upper_ctime );
    PLASSERT( (*this)[lower_ctime] >= lower );
    PLASSERT( (*this)[upper_ctime] <= upper );

    JTimeVec new_timestamps = timestamps_.subVec(lower_ctime,
                                                 upper_ctime - lower_ctime + 1);
    return new Calendar(new_timestamps);
}

Here is the call graph for this function:

string PLearn::Calendar::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

bool PLearn::Calendar::containsTime ( JTime  julian_time,
CTime calendar_time = 0 
) const

Returns true iff julian_time is a valid timestamp.

If specified, argument calendar_time will be filled with the right value if true and will be left unchanged if not.

Definition at line 281 of file Calendar.cc.

References PLearn::fast_exact_is_equal(), getCalendarTime(), and timestamps_.

{
    CTime found = getCalendarTime(julian_time);
    if (fast_exact_is_equal(timestamps_[found], julian_time))
    {
        if (calendar_time)
            *calendar_time = found;
        return true;
    }
    else
        return false;
}

Here is the call graph for this function:

CTime PLearn::Calendar::convertCalendarTime ( const Calendar source_calendar,
const Calendar dest_calendar,
CTime  source_time,
bool  use_lower_bound = true 
) [static]

Converts a calendar.

Definition at line 270 of file Calendar.cc.

References getCalendarTime(), getTime(), isEmpty(), and PLERROR.

{
    if (source_calendar.isEmpty() || dest_calendar.isEmpty())
        PLERROR("In convertCalendarTime(), one of the calendars is empty.");
    return dest_calendar.getCalendarTime(source_calendar.getTime(source_time), use_lower_bound);
}

Here is the call graph for this function:

void PLearn::Calendar::declareMethods ( RemoteMethodMap rmm) [static, protected]

Declare the methods that are remote-callable.

Reimplemented from PLearn::Object.

Definition at line 193 of file Calendar.cc.

References PLearn::Object::_getRemoteMethodMap_(), PLearn::declareMethod(), PLearn::RemoteMethodMap::inherited(), remote_getGlobalCalendar(), and remote_setGlobalCalendar().

{
    // Insert a backpointer to remote methods; note that this
    // different than for declareOptions()
    rmm.inherited(inherited::_getRemoteMethodMap_());

    declareMethod(
        rmm, "setGlobalCalendar", &Calendar::remote_setGlobalCalendar,
        (BodyDoc("Set a global calendar keyed to the given string.\n"
                 "The calendar is created if it does not already exist."),
         ArgDoc ("calendar_name",  "Name of the global calendar to be set"),
         ArgDoc ("calendar_dates", "List of dates that belong to the calendar,\n"
                                   "either in CYYMMDD or YYYYMMDD format")));

    declareMethod(
        rmm, "getGlobalCalendar", &Calendar::remote_getGlobalCalendar,
        (BodyDoc("Return the dates that belong to the global calendar,\n"
                 "given its name"),
         ArgDoc ("calendar_name", "Name of the global calendar to be accessed"),
         RetDoc ("Set of dates that belong to the calendar, in PLearn\n"
                 "Julian Date format")));
}

Here is the call graph for this function:

void PLearn::Calendar::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Object.

Definition at line 173 of file Calendar.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), dwim_timestamps_, and timestamps_.

{
    declareOption(
        ol, "timestamps", &Calendar::timestamps_,
        OptionBase::buildoption,
        "List of the time stamps (in julian time) that are the\n"
        "skeleton of this calendar.");

    declareOption(
        ol, "dwim_timestamps", &Calendar::dwim_timestamps_,
        OptionBase::buildoption,
        "Alternative list of \"human timestamps\" that may be provided in any of\n"
        "the following formats: Julian, CYYMMDD, YYYYMMDD.  The format is\n"
        "recognized automatically.  The dates need not be sorted; they will be\n"
        "sorted automatically.  After construction of the calendar, the option\n"
        "'timestamps' is filled out with the converted Julian timesteps.\n");
        
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

static const PPath& PLearn::Calendar::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Object.

Definition at line 191 of file Calendar.h.

{ return timestamps_.isEmpty(); }
Calendar * PLearn::Calendar::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

CTime PLearn::Calendar::getCalendarTime ( JTime  julian_time,
bool  use_lower_bound = true 
) const

Returns the calendar time corresponding to julian time "julian_time".

If not found, returns the index of the first timestamp that is greater or equal to "julian_time", or the last index if "julian_time" is bigger than all of the timestamps. Returns an error if the calendar contains no timestamps.

Definition at line 228 of file Calendar.cc.

References PLearn::TVec< T >::begin(), PLearn::TVec< T >::end(), PLearn::fast_exact_is_equal(), PLearn::TVec< T >::isEmpty(), last_calendar_time_, last_julian_time_, last_use_lower_bound, PLERROR, and timestamps_.

Referenced by calendarTimeOnOrAfter(), calendarTimeOnOrBefore(), clamp(), containsTime(), convertCalendarTime(), and getLastDayOfMonth().

{
    if (timestamps_.isEmpty())
        PLERROR("In Calendar::getCalendarTime(), this calendar is empty.");
    if (last_calendar_time_ == -1 ||
        !fast_exact_is_equal(last_julian_time_, julian_time) ||
        last_use_lower_bound != use_lower_bound) // *** that one could be made more efficient
    {
        JTimeVec::iterator result;
        if (use_lower_bound)
            result = lower_bound(timestamps_.begin(), timestamps_.end(), julian_time);
        else
            result = upper_bound(timestamps_.begin(), timestamps_.end(), julian_time);
        if (result == timestamps_.end()) // don't go after
            --result;
        last_calendar_time_ = (CTime) (result - timestamps_.begin());
        last_julian_time_ = julian_time;
        last_use_lower_bound = use_lower_bound;
    }
  
    return last_calendar_time_;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const Calendar * PLearn::Calendar::getGlobalCalendar ( const string &  calendar_name) [static]

Return a pointer to the global calendar given the string.

Return a NULL pointer if the calendar does not exist

Definition at line 422 of file Calendar.cc.

References global_calendars.

Referenced by remote_getGlobalCalendar(), and PLearn::VMatLanguage::run().

{
    map<string,PCalendar>::const_iterator it =
        global_calendars.find(calendar_name);
    if (it != global_calendars.end())
        return (const Calendar*)(it->second);
    else
        return 0;
}

Here is the caller graph for this function:

CTime PLearn::Calendar::getLastDayOfMonth ( const PDate day_of_the_month) const

Given a PDate D, returns the last calendar day in the same month than D.

Note that the first or last date of the calendar are returned whenever the given month is out from the calendar boundaries...

Definition at line 251 of file Calendar.cc.

References getCalendarTime(), PLearn::PDate::lastDateOfMonth(), PLearn::PDate::month, PLASSERT, timestamps_, and PLearn::PDate::toJulianDay().

{
    PDate last_day_of_month = day_of_the_month.lastDateOfMonth();
    PLASSERT(day_of_the_month.month==last_day_of_month.month);

    JTime jtime_ldom = last_day_of_month.toJulianDay();
    CTime ctime_ldom = getCalendarTime(jtime_ldom);

    // Was first day of the following month returned?
    if ( ctime_ldom > 0 && timestamps_[ctime_ldom] > jtime_ldom )
    {
        ctime_ldom--;
        PLASSERT( timestamps_[ctime_ldom] <= jtime_ldom );
    }

    return ctime_ldom;
}

Here is the call graph for this function:

OptionList & PLearn::Calendar::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

OptionMap & PLearn::Calendar::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

RemoteMethodMap & PLearn::Calendar::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 76 of file Calendar.cc.

TVec<int> PLearn::Calendar::getResampling ( Calendar other_cal) [inline]

Return the resampling to another calendar or an empty vector if it does not exist.

Definition at line 271 of file Calendar.h.

    { return active_resamplings[other_cal]; }
JTime PLearn::Calendar::getTime ( CTime  calendar_time) const [inline]

Returns timestamp corresponding to "calendar_time".

Definition at line 314 of file Calendar.h.

References PLERROR.

Referenced by calendarTimeOnOrAfter(), calendarTimeOnOrBefore(), and convertCalendarTime().

{
    if (calendar_time < 0 || calendar_time >= timestamps_.length())
        PLERROR("In Calendar::getTime(), argument calendar_time = %d out of bounds.", calendar_time);
    return timestamps_[calendar_time];
}

Here is the caller graph for this function:

const JTimeVec& PLearn::Calendar::getTimeStamps ( ) const [inline]

Returns a reference to the timestamps.

Definition at line 206 of file Calendar.h.

Referenced by operator!=(), and operator==().

{ return timestamps_; }

Here is the caller graph for this function:

PCalendar PLearn::Calendar::intersect ( const TVec< PCalendar > &  calendars) [static]

Return the intersection of a set of calendars.

Definition at line 344 of file Calendar.cc.

References PLearn::TVec< T >::begin(), Calendar(), PLearn::TVec< T >::copy(), PLearn::TVec< T >::end(), PLearn::intersection(), and PLearn::TVec< T >::subVec().

{
    PCalendar intersected = new Calendar;
  
    // In the case of shared calendars, the same calendar may be repeated
    // multiple times in raw_calendars.  Pick out unique copies
    set<PCalendar> calendars(raw_calendars.begin(), raw_calendars.end());
  
    if ( !calendars.empty() )
    {
        set<PCalendar>::iterator it  = calendars.begin();
        set<PCalendar>::iterator end = calendars.end(); 
    
        if ( it != end ) 
        {
            JTimeVec intersection = (*it)->timestamps_.copy();
            JTimeVec::iterator curend = intersection.end();
            ++it;
      
            for (; it != end; ++it)
            {        
                curend = set_intersection(intersection.begin(),
                                          curend,
                                          (*it)->timestamps_.begin(), (*it)->timestamps_.end(),
                                          intersection.begin());
            }
            intersected->timestamps_ =
                intersection.subVec(0, int(curend-intersection.begin())).copy();
        }
    }

    intersected->build();  
    return intersected;
}

Here is the call graph for this function:

bool PLearn::Calendar::isEmpty ( ) const [inline]

Returns true iff this calendar contains no timestamps.

Definition at line 203 of file Calendar.h.

Referenced by convertCalendarTime().

{ return timestamps_.isEmpty(); }

Here is the caller graph for this function:

PCalendar PLearn::Calendar::makeCalendar ( const Vec dates) [static]

This returns a calendar from a vector of "dates".

The following are supported: YYYYMMDD, CYYMMDD, julian dates. The format is recognized automatically. The dates need not be sorted; they will be sorted automatically.

The storage for the dates vector is copied, thus 'dates' is not altered by this function, and can be safely modified afterwards.

Definition at line 102 of file Calendar.cc.

References Calendar(), PLearn::float_to_date(), i, PLearn::TVec< T >::length(), n, PLERROR, PLearn::TVec< T >::size(), PLearn::sortElements(), and PLearn::PDate::toJulianDay().

Referenced by build_(), main(), remote_setGlobalCalendar(), and PLearn::set_global_calendars().

{
    static int Jan1_1900_JDN  = PDate(1900,01,01).toJulianDay();
    static int Dec31_2199_JDN = PDate(2199,12,31).toJulianDay();
    TVec<JTime> jdates(dates.length());
  
    // Start by converting the dates to Julian
    for (int i=0, n=dates.size() ; i<n ; ++i) {
        real date_i = dates[i];

        // YYYYMMDD
        if (date_i >= 19000101 && date_i <= 21991231) {
            int year  = int(date_i / 10000);
            int month = (int(date_i) % 10000) / 100;
            int day   = int(date_i) % 100;
            jdates[i] = PDate(year,month,day).toJulianDay();
        }

        // CYYMMDD (up to 2099/12/31, since 1900/01/01 == JDN-2415021)
        else if (date_i >= 000101 && date_i <= 1991231) {
            jdates[i] = float_to_date(date_i).toJulianDay();
        }

        // Otherwise check it's in the proper range for a JDN
        else if (date_i < Jan1_1900_JDN ||
                 date_i > Dec31_2199_JDN)
            PLERROR("The date value '%g' at index %d could not be interpreted\n"
                    "as a date in YYYYMMDD, CYYMMDD or JDN in the 1900/01/01 to\n"
                    "2199/12/31 range.", date_i, i);
        else
            jdates[i] = JTime(date_i);
    }

    // Next sort by increasing value...
    sortElements(jdates);

    return new Calendar(jdates);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::Calendar::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Object.

Definition at line 222 of file Calendar.cc.

References PLearn::deepCopyField(), PLearn::Object::makeDeepCopyFromShallowCopy(), and timestamps_.

Here is the call graph for this function:

bool PLearn::Calendar::operator!= ( const Calendar cal) [inline]

Returns true iff the calendar has different timestamps.

Definition at line 213 of file Calendar.h.

References getTimeStamps().

    { return (timestamps_ != cal.getTimeStamps()); }

Here is the call graph for this function:

bool PLearn::Calendar::operator== ( const Calendar cal) [inline]

Returns true iff the calendar have the exact same timestamps.

Definition at line 209 of file Calendar.h.

References getTimeStamps().

    { return (timestamps_ == cal.getTimeStamps()); }

Here is the call graph for this function:

JTime PLearn::Calendar::operator[] ( CTime  calendar_time) const [inline]

Definition at line 321 of file Calendar.h.

{
    return getTime(calendar_time);
}
JTimeVec PLearn::Calendar::remote_getGlobalCalendar ( string  calendar_name)

< Shut up compiler

Definition at line 439 of file Calendar.cc.

References getGlobalCalendar(), PLERROR, and timestamps_.

Referenced by declareMethods().

{
    const Calendar* cal = getGlobalCalendar(calendar_name);
    if (! cal) {
        PLERROR("Global calendar '%s' not found", calendar_name.c_str());
        return JTimeVec();                        
    }
    else
        return cal->timestamps_;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::Calendar::remote_setGlobalCalendar ( string  calendar_name,
Vec  calendar_dates 
)

Definition at line 433 of file Calendar.cc.

References makeCalendar(), and setGlobalCalendar().

Referenced by declareMethods().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::Calendar::setGlobalCalendar ( const string &  calendar_name,
PCalendar  calendar 
) [static]

Set a global calendar keyed to the given string.

Definition at line 412 of file Calendar.cc.

References calendar_name, global_calendars, and PLERROR.

Referenced by main(), remote_setGlobalCalendar(), and PLearn::set_global_calendars().

{
    if (calendar_name != "")
        global_calendars[calendar_name] = calendar;
    else
        PLERROR("Calendar::setGlobalCalendar: the calendar name must be specified");
}

Here is the caller graph for this function:

void PLearn::Calendar::setResampling ( Calendar other_cal,
const TVec< int > &  resampling 
) [inline]

Associate or modify a resampling to another calendar.

Definition at line 266 of file Calendar.h.

    { active_resamplings[other_cal] = resampling; }
int PLearn::Calendar::size ( ) const [inline]

Returns the number of timestamps.

Definition at line 217 of file Calendar.h.

Referenced by clamp().

{ return timestamps_.length(); }

Here is the caller graph for this function:

PCalendar PLearn::Calendar::unite ( const TVec< PCalendar > &  calendars) [static]

Return the union of a set of calendars.

Definition at line 317 of file Calendar.cc.

References PLearn::TVec< T >::begin(), Calendar(), std::copy(), and PLearn::TVec< T >::end().

{
    PCalendar united = new Calendar;

    // In the case of shared calendars, the same calendar may be repeated
    // multiple times in raw_calendars.  Pick out unique copies
    set<PCalendar> calendars(raw_calendars.begin(), raw_calendars.end());
  
    if (!calendars.empty())
    {
        set<JTime> timestamps;
        for (set<PCalendar>::iterator it = calendars.begin(); it != calendars.end(); ++it)
        {
            set_union(timestamps.begin(), timestamps.end(),
                      (*it)->timestamps_.begin(),  (*it)->timestamps_.end(),
                      inserter(timestamps, timestamps.begin()));
        }
        united->timestamps_.resize(int(timestamps.size()));
        copy(timestamps.begin(), timestamps.end(), united->timestamps_.begin());
    }

    united->build();
  
    return united;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Object.

Definition at line 191 of file Calendar.h.

Internal map containing memoized resamplings for the calendar.

The interpretation is as follows: for each calendar c in the map, we have a vector of integers v_c. The entry v_c[i] indicates what would be the index in calendar c of the index i in this calendar.

Definition at line 143 of file Calendar.h.

Alternative list of "human timestamps" that may be provided in any of the following formats: Julian, CYYMMDD, YYYYMMDD.

The format is recognized automatically. The dates need not be sorted; they will be sorted automatically. After construction of the calendar, the option 'timestamps' is filled out with the converted Julian timesteps.

Definition at line 159 of file Calendar.h.

Referenced by build_(), and declareOptions().

map< string, PP< Calendar > > PLearn::Calendar::global_calendars [static, protected]

The set of currently-installed global calendars.

Definition at line 146 of file Calendar.h.

Referenced by getGlobalCalendar(), and setGlobalCalendar().

Value returned by last call to getCalendarTime.

Definition at line 134 of file Calendar.h.

Referenced by getCalendarTime().

Input value to last call to getCalendarTime.

Definition at line 131 of file Calendar.h.

Referenced by getCalendarTime().

Last argument used when calling getCalendarTime.

Definition at line 137 of file Calendar.h.

Referenced by getCalendarTime().

The list of julian timestamps that define this calendar.

Definition at line 150 of file Calendar.h.

Referenced by build_(), calendarDiff(), clamp(), containsTime(), declareOptions(), getCalendarTime(), getLastDayOfMonth(), makeDeepCopyFromShallowCopy(), and remote_getGlobalCalendar().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines