MVTime.h

Classes

MVTime -- Class to handle date/time type conversions and I/O (full description)

class MVTime

Types

enum formatTypes

ANGLE
TIME
CLEAN = 4
NO_D = 8
NO_DM = NO_D+16,YMD=TIME+32,DMY=TIME+64,DAY=128
NO_TIME = 256
MJD = TIME+512,DIG2=1024
FITS = TIME+2048,LOCAL=4096
NO_H = NO_D,NO_HM=NO_DM,ANGLE_CLEAN=ANGLE+CLEAN,ANGLE_NO_D=ANGLE+NO_D,ANGLE_NO_DM=ANGLE+NO_DM,ANGLE_CLEAN_NO_D=ANGLE+CLEAN+NO_D,ANGLE_CLEAN_NO_DM=ANGLE+CLEAN+NO_DM,TIME_CLEAN=TIME+CLEAN,TIME_NO_H=TIME+NO_H,TIME_NO_HM=TIME+NO_HM,TIME_CLEAN_NO_H=TIME+CLEAN+NO_H,TIME_CLEAN_NO_HM=TIME+CLEAN+NO_HM,YMD_ONLY=YMD+NO_TIME,MOD_MASK=CLEAN+NO_DM+DAY+NO_TIME+DIG2+LOCAL

Interface

Private Members
friend ostream &operator<<(ostream &os, const MVTime &meas)
friend istream &operator>>(istream &is, MVTime &meas)
friend ostream &operator<<(ostream &os, const MVTime::Format &form)
MVTime()
MVTime(const MVTime &other)
MVTime &operator=(const MVTime &other)
MVTime(Double d)
MVTime(const Quantity &other)
MVTime(const Time &other)
MVTime(const MVEpoch &other)
MVTime(Int yy, Int mm, Double dd, Double d=0.0)
~MVTime()
operator Double() const
static Bool read(Quantity &res, const String &in)
static Bool read(Quantity &res, MUString &in)
static Bool read(Quantity &res, const String &in, Bool chk)
static Bool read(Quantity &res, MUString &in, Bool chk)
Double day() const
Double hour() const
Double minute() const
Double second() const
Quantity get() const
Quantity get(const Unit &inunit) const
Time getTime() const
const String &dayName() const
static const String &dayName(uInt which)
const String &monthName() const
static const String &monthName(uInt which)
uInt weekday() const
uInt month() const
uInt monthday() const
Int year() const
Int ymd() const
uInt yearday() const
uInt yearweek() const
String string() const
String string(MVTime::formatTypes intyp, uInt inprec = 0) const
String string(uInt intyp, uInt inprec) const
String string(uInt inprec) const
String string(const MVTime::Format &form) const
void print(ostream &oss, const MVTime::Format &form) const
static Format setFormat(MVTime::formatTypes intyp, uInt inprec = 0)
static Format setFormat(uInt intyp, uInt inprec)
static Format setFormat(uInt inprec = 0)
static Format setFormat(const Format &form)
static Format getFormat()
static MVTime::formatTypes giveMe(const String &in)
static Double timeZone()
void ymd(Int &yyyy, Int &mm, Int &dd) const

Description

Review Status

Programs:
Tests:

Prerequisite

Etymology

From Measure, Value and Time

Synopsis

An MVTime is a simple Double for date/time conversions and I/O. Its internal value is in MJD. For high precision the MVEpoch class should be used.
It can be constructed from a Double (in which case MJD are assumed), or from a Quantity (Quantum<Double>). Quantities must be in either angle or time units, or from a MVEpoch
The OS/Time class can be used as both input and output. An MVTime(Time) constructor exists, as well as a Time getTime().
Construction from year, month, day is also supported.
Caution Dates before 16 Oct 1582 are considered to be Julian, rather than Gregorian
It has an automatic conversion to Double, so all standard mathematical operations can operate on it.
The class has a number of special functions to obtain data: Output formatting is done with the << statement, with the following rules: The default formatting can be overwritten by a MVTime::setFormat(); statement; which returns an MVTime::Format structure, that can be used in a subsequent one to reset to previous. The format set holds for all MVTime output on all streams.
Temporary formats (i.e. for one MVTime output only), can be set by outputting a format (i.e. stream << MVTime::Format() << ... ).
Caution A setFormat() will also reset any lingering temporary format. A setFormat(getFormat()) will reset without changing. Problems could arise in parallel processors.
Input can be read if the values are in any of the above (non-clean) output formats.
For other formatting practice, the output can be written to a String with the string() member functions.
Strings and input can be converted to an MVTime (or Quantity) by Bool read(Quantity &out, const String &in) and istream >> MVTime &. In the latter case the actual reading is done by the String read, which reads between white-spaces.
The following input formats (note no blanks allowed) are supported (+stands for an optional + or -; v for an unsigned integer; dv for a floating number. [] indicate optional values. Separating codes are case insensitive), numbers(like yyyy) can be of any length: The time can be expressed as described in MVAngle Examples of valid strings:
	ToDay		note case independence
	1996/11/20	20 November 1996 0h UT
	1996/11/20/5:20 20 November 1996 at 5h20m
	20Nov96-5h20m	same (again no case dependence)
	1996-11-20T5:20 same (FITS format, case dependent)

Example

See synopsis

Motivation

To be able to format date/time-like values in user-required ways.

To Do

Member Description

enum formatTypes

Format types

friend ostream &operator<<(ostream &os, const MVTime &meas)

Output a date/time

friend istream &operator>>(istream &is, MVTime &meas)

Input a date/time

friend ostream &operator<<(ostream &os, const MVTime::Format &form)

Set a temporary format

MVTime()

Default constructor: generate a zero value

MVTime(const MVTime &other)

Copy constructor

MVTime &operator=(const MVTime &other)

Copy assignment

MVTime(Double d)

Constructor from Double (in MJD)

MVTime(const Quantity &other)

Constructor from Quantum : value can be an angle or time

Thrown Exceptions

MVTime(const Time &other)

Constructor from Time

MVTime(const MVEpoch &other)

Constructor from MVEpoch;

MVTime(Int yy, Int mm, Double dd, Double d=0.0)

Constructor from yy, mm, dd, dd (all dd with fractions allowed)

~MVTime()

operator Double() const

Conversion operator

static Bool read(Quantity &res, const String &in)
static Bool read(Quantity &res, MUString &in)
static Bool read(Quantity &res, const String &in, Bool chk)
static Bool read(Quantity &res, MUString &in, Bool chk)

Make res time Quantity from string. The String version will accept a time/angle Quantity as well. The chk checks for eos

Double day() const
Double hour() const
Double minute() const
Double second() const
Quantity get() const
Quantity get(const Unit &inunit) const
Time getTime() const

Get value of date/time (MJD) in given units

uInt weekday() const

Get indicated part of the time/date

Mon = 1; Sun = 7;

uInt month() const

Get indicated part of the time/date

Jan =1

const String &dayName() const
static const String &dayName(uInt which)
const String &monthName() const
static const String &monthName(uInt which)
uInt monthday() const
Int year() const
Int ymd() const
uInt yearday() const
uInt yearweek() const

Get indicated part of the time/date

String string() const
String string(MVTime::formatTypes intyp, uInt inprec = 0) const
String string(uInt intyp, uInt inprec) const
String string(uInt inprec) const
String string(const MVTime::Format &form) const
void print(ostream &oss, const MVTime::Format &form) const

Output data

static Format setFormat(MVTime::formatTypes intyp, uInt inprec = 0)
static Format setFormat(uInt intyp, uInt inprec)
static Format setFormat(uInt inprec = 0)
static Format setFormat(const Format &form)

Set default format

static Format getFormat()

Get default format

static MVTime::formatTypes giveMe(const String &in)

Get code belonging to string. 0 if not known

static Double timeZone()

Get time zone offset (in days)

void ymd(Int &yyyy, Int &mm, Int &dd) const

Get the y,m,d values