WXP C++ Library Version 6.74.9
Loading...
Searching...
No Matches
WXP::Date Class Reference

This class stores date and time information. More...

#include "../include/Date.h"

Inheritance diagram for WXP::Date:
WXP::DateVal

Public Member Functions

 Date ()
 Date (int ryear, int rmonth, int rday, int rhour, int rmin, float rsec)
 Date (DateVal &date)
 Date (long secs)
 Date (char *str)
int operator> (const Date &date)
int operator< (const Date &date)
void operator+= (const int rsecs)
int init ()
bool isSet ()
int set (const char *str)
int set (int ryear, int rmonth, int rday, int rhour, int rmin, float rsec)
int set (Date &rdate)
int set (DateVal &date)
int set (DateVal &date, int roff, const char *tz)
int set (DateVal &date, const char *zone, const char *tz)
int set (long secs)
int set ()
int getVals (DateVal &date)
DateVal get ()
int setYear (int val)
int getYear ()
int getYear00 ()
int setMonth (int val)
int getMonth ()
int setDay (int val)
int getDay ()
int setHour (int val)
int getHour ()
int setMinute (int val)
int getMinute ()
int setSecond (float val)
int setFractionalSecond (float val)
float getSecond ()
int getSeconds ()
bool isLeap ()
int setDaylightType (const char dt)
int setDays (int days)
int setTime (int rhour, int rmin, float rsec)
int setTime (float rsecs)
int getDays ()
int addYears (int years)
int addMonths (int months)
int addDays (int days)
int addHours (int hours)
int addMinutes (int mins)
int addSeconds (float secs)
int getDayOfWeek ()
int getJulian ()
int setJulian (int val)
int toString (String &str)
int toText (String &str)
int toText (const char *form, String &str)
int isDaylight ()
int changeTimezone (int roff, const char *tz)
int adjustMinute (int rmonth, int rday, int rhour, int rmin)
int adjustMinute (int rday, int rhour, int rmin)
int adjustMinute (int rhour, int rmin)
int adjustSecond (int rhour, int rmin, int rsec)
int adjustHour (int rmonth, int rday, int rhour)
int adjustHour (int rday, int rhour)
int adjustHour (int rhour)
int fix ()
int print ()
int printSeconds ()

Static Public Member Functions

static long getCurrentSeconds ()
static bool isYearLeap (int year)
static int setJulian (int year, int jday, int &month, int &day)
static int getJulian (int year, int month, int day)

Detailed Description

This class stores date and time information.

Author
Dan Vietor

Constructor & Destructor Documentation

◆ Date() [1/5]

Date::Date ( )

Constructor. Initializes values and sets to current time

References init().

Referenced by set().

◆ Date() [2/5]

Date::Date ( int ryear,
int rmonth,
int rday,
int rhour,
int rmin,
float rsec )

Constructor. Initializes values and sets individual values

Parameters
ryearThe year (yyyy or 1900+yyy)
rmonthThe month (1-12)
rdayThe day (1-31)
rhourThe hour (0-23)
rminThe minute (0-59)
rsecThe second (0-59.99999)

References init(), and set().

◆ Date() [3/5]

Date::Date ( DateVal & date)

Constructor. Initializes values and sets to DateVal values

Parameters
dateDate values from DateVal structure.

References WXP::DateVal::DateVal(), init(), and set().

◆ Date() [4/5]

Date::Date ( long rsecs)

Constructor. Initializes values and sets values from seconds since 1/1/1970

Parameters
rsecsSeconds since 1/1/1970 (Unix time)

References init(), and set().

◆ Date() [5/5]

Date::Date ( char * str)

Constructor. Sets values from string

Parameters
strDate as a string "yyyymmddhhnn.nnn"

References init(), and set().

Member Function Documentation

◆ addDays()

int Date::addDays ( int days)

Adds days to date values and recomputes

Parameters
daysNumber of days to offset

References WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::sec, and set().

Referenced by adjustHour(), adjustHour(), and WXP::NameConv::setLatest().

◆ addHours()

int Date::addHours ( int hours)

◆ addMinutes()

int Date::addMinutes ( int mins)

Adds minutes to date values and recomputes

Parameters
minsNumber of minutes to offset

References WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::sec, and set().

◆ addMonths()

int Date::addMonths ( int months)

Adds months to date values and recomputes

Parameters
monthsNumber of months to offset

References WXP::DateVal::computeSecs(), WXP::DateVal::month, and WXP::DateVal::year.

Referenced by adjustHour(), and WXP::NameConv::setLatest().

◆ addSeconds()

int Date::addSeconds ( float rsec)

◆ addYears()

int Date::addYears ( int years)

Adds years to date values and recomputes

Parameters
yearsNumber of years to offset

References WXP::DateVal::computeSecs(), and WXP::DateVal::year.

Referenced by WXP::NameConv::setLatest().

◆ adjustHour() [1/3]

int Date::adjustHour ( int rday,
int rhour )

Adjusts the date according to new day/hour

Parameters
rdayNew day
rhourNew hour

References addDays(), addMonths(), WXP::DateVal::day, WXP::DateVal::hour, setDay(), setHour(), and WXP::DateVal::validate().

◆ adjustHour() [2/3]

int Date::adjustHour ( int rhour)

Adjusts the date according to new hour

Parameters
rhourNew hour

References addDays(), WXP::DateVal::hour, setHour(), and WXP::DateVal::validate().

◆ adjustHour() [3/3]

int Date::adjustHour ( int rmonth,
int rday,
int rhour )

◆ adjustMinute() [1/3]

int Date::adjustMinute ( int rday,
int rhour,
int rmin )

Adjusts the date according to new day/hour/minute

Parameters
rdayNew day
rhourNew hour
rminNew minutes

References adjustHour(), and setMinute().

◆ adjustMinute() [2/3]

int Date::adjustMinute ( int rhour,
int rmin )

Adjusts the date according to new hour/minute

Parameters
rhourNew hour
rminNew minutes

References adjustHour(), and setMinute().

◆ adjustMinute() [3/3]

int Date::adjustMinute ( int rmonth,
int rday,
int rhour,
int rmin )

Adjusts the date according to new month/day/hour/minute

Parameters
rmonthNew month
rdayNew day
rhourNew hour
rminNew minute

References adjustHour(), and setMinute().

Referenced by WXP::SynopTool::decode(), WXP::SfcWxpFile::read(), WXP::SfcXmlFile::read(), WXP::WatchFile::read(), and WXP::WmoIngest::setAction().

◆ adjustSecond()

int Date::adjustSecond ( int rhour,
int rmin,
int rsec )

Adjusts the date according to new hour/minute/seconds

Parameters
rhourNew hour
rminNew minutes
rsecNew seconds

References adjustHour(), setMinute(), and setSecond().

◆ changeTimezone()

int Date::changeTimezone ( int roff,
const char * tz )

Changes the time zone parameters

Parameters
roffTime zone offset in seconds (EST = -18000)
tzString describing timezone (EST)

References WXP::StrLib::copy(), WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::sec, and set().

Referenced by WXP::DateTool::createLabel().

◆ fix()

◆ get()

DateVal Date::get ( )

◆ getCurrentSeconds()

long Date::getCurrentSeconds ( )
static

This function returns the current time in seconds

Returns
Seconds since 1/1/1970 (Unix time)

Referenced by set().

◆ getDay()

◆ getDayOfWeek()

int Date::getDayOfWeek ( )

Gets the day of week

Returns
Day of week (0-6)

Referenced by WXP::DateTool::createLabel().

◆ getDays()

int Date::getDays ( )

Gets number of days since 1/1/1970

Returns
Days since 1/1/1970

References WXP::DateVal::day, WXP::DateVal::month, WXP::DateVal::num_day, and WXP::DateVal::year.

◆ getHour()

◆ getJulian() [1/2]

int Date::getJulian ( )

Gets the julian day

Returns
Julian day of year (1-366)

Referenced by WXP::NameConv::encode(), and WXP::WmoIngest::setAction().

◆ getJulian() [2/2]

int Date::getJulian ( int year,
int month,
int day )
static

◆ getMinute()

◆ getMonth()

int WXP::Date::getMonth ( )
inline

Gets the month

Returns
Month

References WXP::DateVal::month.

Referenced by WXP::DateTool::createLabel(), WXP::NameConv::encode(), and WXP::NameConv::setLatest().

◆ getSecond()

float WXP::Date::getSecond ( )
inline

Gets the seconds

Returns
Seconds

References WXP::DateVal::sec.

Referenced by WXP::DateTool::createLabel(), and WXP::LightPlot::draw().

◆ getSeconds()

◆ getVals()

int Date::getVals ( DateVal & date)

Gets the date values

Return values
dateDateVal structure to receive values

References WXP::DateVal::DateVal(), WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::DateVal::month, WXP::DateVal::sec, and WXP::DateVal::year.

◆ getYear()

int WXP::Date::getYear ( )
inline

Gets the year

Returns
Year (yyyy)

References WXP::DateVal::year.

Referenced by WXP::NameConv::setLatest().

◆ getYear00()

int Date::getYear00 ( )

Gets the year (from 1900)

Returns
Years since 1900

References WXP::Const::MISS, and WXP::DateVal::year.

Referenced by WXP::DateTool::createLabel().

◆ init()

◆ isLeap()

bool Date::isLeap ( )

Checks if year a leap year

Returns
True if a leap year

References isYearLeap(), and WXP::DateVal::year.

Referenced by setDays().

◆ isSet()

bool Date::isSet ( )

Checks to see if date values are set

Returns
True if set

References WXP::Const::MISS.

Referenced by WXP::DateTool::createLabel(), and WXP::LightPlot::draw().

◆ isYearLeap()

bool Date::isYearLeap ( int year)
static

Checks for leap year given a year

Parameters
yearYear (yyyy)
Returns
True if a leap year

References WXP::DateVal::year.

Referenced by getJulian(), isLeap(), and setJulian().

◆ print()

int Date::print ( )

Prints date values to stdout. The format is "\%H:\%M:\%S\%Z \%e \%b \%Y"

See also
Date::toText(char *,String &)

References WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::month, WXP::DateVal::sec, and WXP::DateVal::year.

Referenced by WXP::LightPlot::draw(), WXP::DateTool::print(), and WXP::NameConv::setLatest().

◆ printSeconds()

int Date::printSeconds ( )

Prints the internal seconds (since 1/1/70)

◆ set() [1/8]

int Date::set ( )

Sets the date values based on current time

References getCurrentSeconds(), and set().

Referenced by addDays(), addHours(), addMinutes(), addSeconds(), changeTimezone(), Date(), Date(), Date(), Date(), set(), and set().

◆ set() [2/8]

◆ set() [3/8]

int WXP::Date::set ( Date & rdate)
inline

Sets date given another Date class

References Date().

◆ set() [4/8]

◆ set() [5/8]

int Date::set ( DateVal & date,
const char * zn,
const char * tz )

Sets the date values with DateVal values and timezone

Parameters
dateDate values from DateVal structure.
zoneOffset in hours + daylight type (-5 for EST, -5U for EST/EDT)
tzCharacter string describing timezone (EST)

References WXP::DateVal::computeSecs(), WXP::StrLib::copy(), WXP::DateVal::DateVal(), WXP::DateVal::day, WXP::DateVal::hour, init(), WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::month, WXP::DateVal::sec, setJulian(), WXP::DateVal::validate(), and WXP::DateVal::year.

◆ set() [6/8]

int Date::set ( DateVal & date,
int roff,
const char * tz )

Sets the date values with DateVal values and timezone

Parameters
dateDate values from DateVal structure.
roffOffset in seconds from UTC of timezone (-18000 for EST)
tzCharacter string describing timezone (EST)

References WXP::DateVal::computeSecs(), WXP::StrLib::copy(), WXP::DateVal::DateVal(), WXP::DateVal::day, WXP::DateVal::hour, init(), WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::month, WXP::DateVal::sec, setJulian(), WXP::DateVal::validate(), and WXP::DateVal::year.

◆ set() [7/8]

int Date::set ( int ryear,
int rmonth,
int rday,
int rhour,
int rmin,
float rsec )

Sets the date values individually.

Parameters
ryearThe year (yyyy or 1900+yyy)
rmonthThe month (1-12)
rdayThe day (1-31)
rhourThe hour (0-23)
rminThe minute (0-59)
rsecThe second (0-59.99999)

References WXP::DateVal::computeSecs(), WXP::DateVal::day, WXP::DateVal::hour, init(), WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::month, WXP::DateVal::sec, setJulian(), WXP::DateVal::validate(), and WXP::DateVal::year.

◆ set() [8/8]

int Date::set ( long rsecs)

Sets the date values based on time in seconds

Parameters
rsecsSeconds since 1/1/1970 (Unix time)

References WXP::DateVal::day, WXP::DateVal::hour, WXP::DateVal::min, WXP::DateVal::month, WXP::DateVal::sec, and WXP::DateVal::year.

◆ setDay()

int Date::setDay ( int val)

Sets the day

Parameters
valDay (1-31)

References WXP::DateVal::computeSecs(), WXP::DateVal::day, and WXP::Const::MISS.

Referenced by adjustHour(), adjustHour(), and WXP::NameConv::setLatest().

◆ setDaylightType()

int Date::setDaylightType ( const char dt)

Sets the type of daylight time

◆ setDays()

int Date::setDays ( int days)

Sets date values using days since 1/1/1970

Parameters
daysDays since 1/1/1970

References WXP::DateVal::computeSecs(), WXP::DateVal::day, isLeap(), WXP::DateVal::month, WXP::DateVal::num_day, WXP::DateVal::num_day_leap, and WXP::DateVal::year.

◆ setFractionalSecond()

int Date::setFractionalSecond ( float val)

Sets the fractional seconds

Parameters
valFractional seconds (0-0.999999)

References WXP::Const::MISS, and WXP::DateVal::sec.

◆ setHour()

int Date::setHour ( int val)

Sets the hour

Parameters
valHour (0-23)

References WXP::DateVal::computeSecs(), WXP::DateVal::hour, and WXP::Const::MISS.

Referenced by adjustHour(), adjustHour(), adjustHour(), and WXP::NameConv::setLatest().

◆ setJulian() [1/2]

int Date::setJulian ( int val)

◆ setJulian() [2/2]

int Date::setJulian ( int year,
int jday,
int & month,
int & day )
static

Sets day of year from Julian day

Parameters
yearYear to use (test for leap year)
jdayJulian day (1-366)
Return values
monthMonth of year
dayDay of year

References WXP::DateVal::day, isYearLeap(), WXP::DateVal::month, WXP::DateVal::num_day, WXP::DateVal::num_day_leap, and WXP::DateVal::year.

◆ setMinute()

◆ setMonth()

int Date::setMonth ( int val)

Sets the month

Parameters
valMonth (1-12)

References WXP::DateVal::computeSecs(), WXP::Const::MISS, and WXP::DateVal::month.

Referenced by adjustHour(), and WXP::NameConv::setLatest().

◆ setSecond()

int Date::setSecond ( float val)

Sets the second

Parameters
valSecond (0-59.9999)

References WXP::DateVal::computeSecs(), WXP::Const::MISS, and WXP::DateVal::sec.

Referenced by adjustSecond().

◆ setTime() [1/2]

int Date::setTime ( float rsecs)

Sets time using seconds since midnight

Parameters
rsecsSeconds since midnight

References WXP::DateVal::computeSecs(), WXP::DateVal::hour, WXP::DateVal::min, and WXP::DateVal::sec.

◆ setTime() [2/2]

int Date::setTime ( int rhour,
int rmin,
float rsec )

Sets the time values only

Parameters
rhourThe hour (0-23)
rminThe minute (0-59)
rsecThe second (0-59.99999)

References WXP::DateVal::computeSecs(), WXP::DateVal::hour, init(), WXP::DateVal::min, WXP::DateVal::sec, and WXP::DateVal::validate().

◆ setYear()

int Date::setYear ( int val)

Sets the year

Parameters
valYear (yyyy or 1900+yyy)

References WXP::DateVal::computeSecs(), WXP::Const::MISS, and WXP::DateVal::year.

◆ toString()

int Date::toString ( String & str)

Output date values to string

Return values
strOutput string using format "%Y%m%d%H%M%S"
See also
Date::toText(char *,String &)

References toText().

◆ toText() [1/2]

int Date::toText ( const char * form,
String & str )

Creates a string from the date values

Parameters
formFormat string
%a = day of week (SUN-SAT)
%b = month (JAN-DEC)
%Y = year (yyyy)
%y = year (yy)
%m = month (mm)
%d = day (dd)
%e = day ( d or dd)
%j = julian day (001-366)
%H = hour (00-23)
%l = hour (00-12)
%p = AM/PM
%M = minute (00-59)
%S = second (00-59)
%s = second (00.0000-59.9999)
%u = day of week (0-6)
%Z = time zone string
Return values
strOutput string

References WXP::String::append(), WXP::String::aprintf(), WXP::String::clear(), WXP::DateVal::day, WXP::StrLib::equal(), WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::month, WXP::DateVal::sec, and WXP::DateVal::year.

◆ toText() [2/2]

int Date::toText ( String & str)

Output date values to string

Return values
strOutput string using format "%H:%M:%S%Z %e %b %Y"
See also
Date::toText(char *,String &)

References WXP::DateVal::hour, WXP::DateVal::min, WXP::Const::MISS, WXP::DateVal::sec, and toText().

Referenced by WXP::DateTool::getCurrent(), WXP::DateTool::getCurrent(), toString(), and toText().


The documentation for this class was generated from the following files: