| 1 |
/* -*-C++-*- |
| 2 |
|
| 3 |
"$Id: Fl_Date.H,v 1.4 2000/03/30 04:43:56 davefreese Exp $" |
| 4 |
|
| 5 |
Copyright 1999-2000 by the Dave Freese & the Flek development team. |
| 6 |
*/ |
| 7 |
// ---------------------------------------------------------------------------- |
| 8 |
// Copyright (C) 2014 |
| 9 |
// David Freese, W1HKJ |
| 10 |
// |
| 11 |
// This file is part of flmsg |
| 12 |
// |
| 13 |
// flrig is free software; you can redistribute it and/or modify |
| 14 |
// it under the terms of the GNU General Public License as published by |
| 15 |
// the Free Software Foundation; either version 3 of the License, or |
| 16 |
// (at your option) any later version. |
| 17 |
// |
| 18 |
// flrig is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 |
// ---------------------------------------------------------------------------- |
| 26 |
|
| 27 |
#ifndef DATE_H |
| 28 |
#define DATE_H |
| 29 |
|
| 30 |
#include <iosfwd> |
| 31 |
|
| 32 |
typedef enum { |
| 33 |
SUNDAY, |
| 34 |
MONDAY, |
| 35 |
TUESDAY, |
| 36 |
WEDNESDAY, |
| 37 |
THURSDAY, |
| 38 |
FRIDAY, |
| 39 |
SATURDAY |
| 40 |
} weekday_t; |
| 41 |
|
| 42 |
typedef enum { |
| 43 |
JANUARY = 1, |
| 44 |
FEBRUARY, |
| 45 |
MARCH, |
| 46 |
APRIL, |
| 47 |
MAY, |
| 48 |
JUNE, |
| 49 |
JULY, |
| 50 |
AUGUST, |
| 51 |
SEPTEMBER, |
| 52 |
OCTOBER, |
| 53 |
NOVEMBER, |
| 54 |
DECEMBER |
| 55 |
} month_t; |
| 56 |
|
| 57 |
class Date { |
| 58 |
friend std::ostream &operator<<(std::ostream &, Date &); |
| 59 |
|
| 60 |
protected: |
| 61 |
int year; |
| 62 |
int month; |
| 63 |
int day; |
| 64 |
int fmt; |
| 65 |
static const int mdays[]; |
| 66 |
static const int jdays[][13]; |
| 67 |
static const char *month_name[]; |
| 68 |
void helpIncrement(); |
| 69 |
|
| 70 |
public: |
| 71 |
Date(); |
| 72 |
Date( int m, int d, int y ); |
| 73 |
|
| 74 |
void setDate( int, int, int ); // set the date |
| 75 |
void setDate( Date & ); |
| 76 |
void setFormat (int); |
| 77 |
void today(); // set date to the present day |
| 78 |
void Year( int ); |
| 79 |
int Year(); |
| 80 |
void Month( int ); |
| 81 |
int Month(); |
| 82 |
void Day( int ); |
| 83 |
int Day(); |
| 84 |
|
| 85 |
void previous_month (); |
| 86 |
void next_month (); |
| 87 |
void previous_year (); |
| 88 |
void next_year (); |
| 89 |
|
| 90 |
bool endOfMonth( int ); |
| 91 |
|
| 92 |
bool leapYear (int); |
| 93 |
bool leapYear () { return leapYear (year); } |
| 94 |
bool isleapyear (int year) { return leapYear (year); } |
| 95 |
bool isleapyear () { return isleapyear (year); } |
| 96 |
|
| 97 |
int daysinmonth (int, int); |
| 98 |
int daysinmonth () |
| 99 |
{ return daysinmonth (month, isleapyear (year)); } |
| 100 |
|
| 101 |
bool isvalid (int, int, int); |
| 102 |
bool datevalid (int year, int mon, int day) |
| 103 |
{ return isvalid (mon, day, year); } |
| 104 |
bool datevalid () |
| 105 |
{ return isvalid (month, day, year); } |
| 106 |
|
| 107 |
int dayofyear (int, int, int); |
| 108 |
int dayofyear () |
| 109 |
{ return dayofyear (year, month, day); } |
| 110 |
|
| 111 |
int dayofepoch (int, int, int); |
| 112 |
int dayofepoch () |
| 113 |
{ return dayofepoch (year, month, day); } |
| 114 |
|
| 115 |
int dayofweek (int, int, int); |
| 116 |
int dayofweek () |
| 117 |
{ return dayofweek (year, month, day); } |
| 118 |
|
| 119 |
char *szDate (int); |
| 120 |
char *szDate (); |
| 121 |
double dJulian (); |
| 122 |
|
| 123 |
bool operator==( const Date & ); |
| 124 |
bool operator!=( const Date & ); |
| 125 |
bool operator<( const Date & ); |
| 126 |
bool operator>( const Date & ); |
| 127 |
void operator=( const Date & ); |
| 128 |
const Date &operator+=( int); // add days, modify object |
| 129 |
Date &operator++(); // pre-increment operator |
| 130 |
Date operator++( int ); // post-increment operator |
| 131 |
|
| 132 |
}; |
| 133 |
|
| 134 |
extern bool date_local_; |
| 135 |
|
| 136 |
#endif |