casacore
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
casacore::MVTime Class Reference

More...

#include <MVTime.h>

Classes

class  Format
 Format structure. More...
 

Public Types

enum  formatTypes {
  ANGLE ,
  TIME ,
  CLEAN ,
  NO_D ,
  NO_DM ,
  YMD ,
  DMY ,
  DAY ,
  NO_TIME ,
  MJD ,
  DIG2 ,
  FITS ,
  LOCAL ,
  USE_SPACE ,
  ALPHA ,
  USE_Z ,
  ISO ,
  BOOST ,
  NO_H ,
  NO_HM ,
  ANGLE_CLEAN ,
  ANGLE_NO_D ,
  ANGLE_NO_DM ,
  ANGLE_CLEAN_NO_D ,
  ANGLE_CLEAN_NO_DM ,
  TIME_CLEAN ,
  TIME_NO_H ,
  TIME_NO_HM ,
  TIME_CLEAN_NO_H ,
  TIME_CLEAN_NO_HM ,
  YMD_ONLY ,
  MOD_MASK
}
 Format types. More...
 

Public Member Functions

 MVTime ()
 Default constructor: generate a zero value. More...
 
 MVTime (const MVTime &other)
 Copy constructor. More...
 
MVTimeoperator= (const MVTime &other)
 Copy assignment. More...
 
 MVTime (Double d)
 Constructor from Double (in MJD) More...
 
 MVTime (const Quantity &other)
 Constructor from Quantum : value can be an angle or time. More...
 
 MVTime (const Time &other)
 Constructor from Time. More...
 
 MVTime (const MVEpoch &other)
 Constructor from MVEpoch;. More...
 
 MVTime (Int yy, Int mm, Double dd, Double d=0.0)
 Constructor from yy, mm, dd, dd (all dd with fractions allowed) More...
 
 ~MVTime ()
 
 operator Double () const
 Conversion operator. More...
 
Double day () const
 Get value of date/time (MJD) in given units. More...
 
Double hour () const
 
Double minute () const
 
Double second () const
 
Quantity get () const
 
Quantity get (const Unit &inunit) const
 
Time getTime () const
 
const StringdayName () const
 Get indicated part of the time/date. More...
 
const StringmonthName () const
 
uInt weekday () const
 Mon = 1; Sun = 7;. More...
 
uInt month () const
 Jan =1. More...
 
uInt monthday () const
 
Int year () const
 
Int ymd () const
 
uInt yearday () const
 
uInt yearweek () const
 
String string () const
 Output data. More...
 
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 Public Member Functions

static Bool read (Quantity &res, const String &in, Bool chk=True)
 Make res time Quantity from string. More...
 
static Bool read (Quantity &res, MUString &in, Bool chk=True)
 
static Bool read (Quantity &res, const String &in, Bool chk, Bool throwExcp)
 
static Bool read (Quantity &res, MUString &in, Bool chk, Bool throwExcp)
 
static const StringdayName (uInt which)
 
static const StringmonthName (uInt which)
 
static Format setFormat (MVTime::formatTypes intyp, uInt inprec=0)
 Set default format
Warning: It is thread-unsafe to print using the setFormat functions because they change a static class member; The only thred-safe way to print a time is to use the print function above;
More...
 
static Format setFormat (uInt intyp, uInt inprec)
 
static Format setFormat (uInt inprec=0)
 
static Format setFormat (const Format &form)
 
static Format getFormat ()
 Get default format. More...
 
static MVTime::formatTypes giveMe (const String &in)
 Get code belonging to string. More...
 
static Double timeZone ()
 Get time zone offset (in days) More...
 

Private Member Functions

void ymd (Int &yyyy, Int &mm, Int &dd) const
 Get the y,m,d values. More...
 

Private Attributes

Double val
 Value. More...
 

Static Private Attributes

static MVTime::Format defaultFormat
 Default format. More...
 
static MVTime::Format interimFormat
 Temporary format. More...
 
static Bool interimSet
 

Friends

ostream & operator<< (ostream &os, const MVTime &meas)
 Output a date/time. More...
 
istream & operator>> (istream &is, MVTime &meas)
 Input a date/time. More...
 
ostream & operator<< (ostream &os, const MVTime::Format &form)
 Set a temporary format. More...
 

Detailed Description

Class to handle date/time type conversions and I/O

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25
Test programs:
tMeasure

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.
Note that using a temporary format is inherently thread-unsafe because the format is kept in a static variable. Another thread may overwrite the format just set. The only thread-safe way to format an MVTime is using a print or string that accepts a Format object.

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 separator between date and time part can be a slash (as shown below), a hyphen, or one or more spaces.

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

Definition at line 270 of file MVTime.h.

Member Enumeration Documentation

◆ formatTypes

Format types.

Enumerator
ANGLE 
TIME 
CLEAN 
NO_D 
NO_DM 
YMD 
DMY 
DAY 
NO_TIME 
MJD 
DIG2 
FITS 
LOCAL 
USE_SPACE 
ALPHA 
USE_Z 
ISO 
BOOST 
NO_H 
NO_HM 
ANGLE_CLEAN 
ANGLE_NO_D 
ANGLE_NO_DM 
ANGLE_CLEAN_NO_D 
ANGLE_CLEAN_NO_DM 
TIME_CLEAN 
TIME_NO_H 
TIME_NO_HM 
TIME_CLEAN_NO_H 
TIME_CLEAN_NO_HM 
YMD_ONLY 
MOD_MASK 

Definition at line 276 of file MVTime.h.

Constructor & Destructor Documentation

◆ MVTime() [1/7]

casacore::MVTime::MVTime ( )

Default constructor: generate a zero value.

◆ MVTime() [2/7]

casacore::MVTime::MVTime ( const MVTime other)

Copy constructor.

◆ MVTime() [3/7]

casacore::MVTime::MVTime ( Double  d)

Constructor from Double (in MJD)

◆ MVTime() [4/7]

casacore::MVTime::MVTime ( const Quantity other)

Constructor from Quantum : value can be an angle or time.

Thrown Exceptions

◆ MVTime() [5/7]

casacore::MVTime::MVTime ( const Time other)

Constructor from Time.

◆ MVTime() [6/7]

casacore::MVTime::MVTime ( const MVEpoch other)

Constructor from MVEpoch;.

◆ MVTime() [7/7]

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

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

◆ ~MVTime()

casacore::MVTime::~MVTime ( )

Member Function Documentation

◆ day()

Double casacore::MVTime::day ( ) const

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

◆ dayName() [1/2]

const String& casacore::MVTime::dayName ( ) const

Get indicated part of the time/date.

◆ dayName() [2/2]

static const String& casacore::MVTime::dayName ( uInt  which)
static

◆ get() [1/2]

Quantity casacore::MVTime::get ( ) const

◆ get() [2/2]

Quantity casacore::MVTime::get ( const Unit inunit) const

◆ getFormat()

static Format casacore::MVTime::getFormat ( )
static

Get default format.

◆ getTime()

Time casacore::MVTime::getTime ( ) const

◆ giveMe()

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

Get code belonging to string.

0 if not known

◆ hour()

Double casacore::MVTime::hour ( ) const

◆ minute()

Double casacore::MVTime::minute ( ) const

◆ month()

uInt casacore::MVTime::month ( ) const

Jan =1.

◆ monthday()

uInt casacore::MVTime::monthday ( ) const

◆ monthName() [1/2]

const String& casacore::MVTime::monthName ( ) const

◆ monthName() [2/2]

static const String& casacore::MVTime::monthName ( uInt  which)
static

◆ operator Double()

casacore::MVTime::operator Double ( ) const

Conversion operator.

◆ operator=()

MVTime& casacore::MVTime::operator= ( const MVTime other)

Copy assignment.

◆ print()

void casacore::MVTime::print ( ostream &  oss,
const MVTime::Format form 
) const

◆ read() [1/4]

static Bool casacore::MVTime::read ( Quantity res,
const String in,
Bool  chk,
Bool  throwExcp 
)
static

◆ read() [2/4]

static Bool casacore::MVTime::read ( Quantity res,
const String in,
Bool  chk = True 
)
static

Make res time Quantity from string.

The String version will accept a time/angle Quantity as well. It returns False in case of an error. chk=True means that the entire string should be consumed. throwExcp=True means that an exception is thrown in case of an error.

◆ read() [3/4]

static Bool casacore::MVTime::read ( Quantity res,
MUString in,
Bool  chk,
Bool  throwExcp 
)
static

◆ read() [4/4]

static Bool casacore::MVTime::read ( Quantity res,
MUString in,
Bool  chk = True 
)
static

◆ second()

Double casacore::MVTime::second ( ) const

◆ setFormat() [1/4]

static Format casacore::MVTime::setFormat ( const Format form)
static

◆ setFormat() [2/4]

static Format casacore::MVTime::setFormat ( MVTime::formatTypes  intyp,
uInt  inprec = 0 
)
static

Set default format
Warning: It is thread-unsafe to print using the setFormat functions because they change a static class member; The only thred-safe way to print a time is to use the print function above;

◆ setFormat() [3/4]

static Format casacore::MVTime::setFormat ( uInt  inprec = 0)
static

◆ setFormat() [4/4]

static Format casacore::MVTime::setFormat ( uInt  intyp,
uInt  inprec 
)
static

◆ string() [1/5]

String casacore::MVTime::string ( ) const

Output data.


Warning: The first function below is thread-unsafe because it uses the result of the setFormat function which changes a static class member; The other functions are thread-safe because the format is directly given;

◆ string() [2/5]

String casacore::MVTime::string ( const MVTime::Format form) const

◆ string() [3/5]

String casacore::MVTime::string ( MVTime::formatTypes  intyp,
uInt  inprec = 0 
) const

◆ string() [4/5]

String casacore::MVTime::string ( uInt  inprec) const

◆ string() [5/5]

String casacore::MVTime::string ( uInt  intyp,
uInt  inprec 
) const

◆ timeZone()

static Double casacore::MVTime::timeZone ( )
static

Get time zone offset (in days)

◆ weekday()

uInt casacore::MVTime::weekday ( ) const

Mon = 1; Sun = 7;.

◆ year()

Int casacore::MVTime::year ( ) const

◆ yearday()

uInt casacore::MVTime::yearday ( ) const

◆ yearweek()

uInt casacore::MVTime::yearweek ( ) const

◆ ymd() [1/2]

Int casacore::MVTime::ymd ( ) const

◆ ymd() [2/2]

void casacore::MVTime::ymd ( Int yyyy,
Int mm,
Int dd 
) const
private

Get the y,m,d values.

Friends And Related Function Documentation

◆ operator<< [1/2]

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

Output a date/time.

Output

◆ operator<< [2/2]

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

Set a temporary format.

◆ operator>>

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

Input a date/time.

Member Data Documentation

◆ defaultFormat

MVTime::Format casacore::MVTime::defaultFormat
staticprivate

Default format.

Definition at line 442 of file MVTime.h.

◆ interimFormat

MVTime::Format casacore::MVTime::interimFormat
staticprivate

Temporary format.

Definition at line 445 of file MVTime.h.

◆ interimSet

Bool casacore::MVTime::interimSet
staticprivate

Definition at line 446 of file MVTime.h.

◆ val

Double casacore::MVTime::val
private

Value.

Definition at line 440 of file MVTime.h.


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