2007-10-14 17:53:53 +04:00
|
|
|
/*
|
2008-08-29 23:26:58 +04:00
|
|
|
* Copyright 2007-2008, Haiku, Inc. All Rights Reserved.
|
2007-10-14 17:53:53 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _DATE_TIME_H_
|
|
|
|
#define _DATE_TIME_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
|
2008-08-29 23:26:58 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
|
|
|
|
|
2007-10-14 17:53:53 +04:00
|
|
|
enum time_type {
|
|
|
|
B_GMT_TIME,
|
|
|
|
B_LOCAL_TIME
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BTime {
|
|
|
|
public:
|
|
|
|
BTime();
|
|
|
|
BTime(int32 hour, int32 minute, int32 second);
|
|
|
|
~BTime();
|
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
static BTime CurrentTime(time_type type);
|
|
|
|
bool SetTime(int32 hour, int32 minute, int32 second);
|
|
|
|
|
|
|
|
int32 Hour() const;
|
|
|
|
int32 Minute() const;
|
|
|
|
int32 Second() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32 fHour;
|
|
|
|
int32 fMinute;
|
|
|
|
int32 fSecond;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BDate {
|
|
|
|
public:
|
|
|
|
BDate();
|
|
|
|
BDate(int32 year, int32 month, int32 day);
|
|
|
|
~BDate();
|
|
|
|
|
|
|
|
bool IsValid() const;
|
2008-09-01 17:11:29 +04:00
|
|
|
bool IsValid(const BDate& date) const;
|
|
|
|
bool IsValid(int32 year, int32 month, int32 day) const;
|
2007-10-14 17:53:53 +04:00
|
|
|
|
|
|
|
static BDate CurrentDate(time_type type);
|
2008-09-01 17:11:29 +04:00
|
|
|
|
|
|
|
BDate Date() const;
|
|
|
|
bool SetDate(const BDate& date);
|
|
|
|
|
2007-10-14 17:53:53 +04:00
|
|
|
bool SetDate(int32 year, int32 month, int32 day);
|
2008-09-01 17:11:29 +04:00
|
|
|
void GetDate(int32* year, int32* month, int32* day);
|
2008-08-31 19:37:37 +04:00
|
|
|
|
2008-08-30 20:13:05 +04:00
|
|
|
void AddDays(int32 days);
|
2008-08-31 19:37:37 +04:00
|
|
|
void AddYears(int32 years);
|
|
|
|
void AddMonths(int32 months);
|
2007-10-14 17:53:53 +04:00
|
|
|
|
|
|
|
int32 Day() const;
|
|
|
|
int32 Year() const;
|
|
|
|
int32 Month() const;
|
2008-09-01 17:11:29 +04:00
|
|
|
int32 Difference(const BDate& date) const;
|
2007-10-14 17:53:53 +04:00
|
|
|
|
|
|
|
int32 DayOfWeek() const;
|
|
|
|
int32 DayOfYear() const;
|
|
|
|
|
|
|
|
int32 WeekNumber() const;
|
|
|
|
bool IsLeapYear(int32 year) const;
|
|
|
|
|
|
|
|
int32 DaysInYear() const;
|
|
|
|
int32 DaysInMonth() const;
|
|
|
|
|
|
|
|
BString ShortDayName(int32 day) const;
|
|
|
|
BString ShortMonthName(int32 month) const;
|
|
|
|
|
|
|
|
BString LongDayName(int32 day) const;
|
|
|
|
BString LongMonthName(int32 month) const;
|
|
|
|
|
2008-09-01 17:11:29 +04:00
|
|
|
int32 DateToJulianDay() const;
|
|
|
|
static BDate JulianDayToDate(int32 julianDay);
|
|
|
|
|
|
|
|
bool operator!=(const BDate& date) const;
|
|
|
|
bool operator==(const BDate& date) const;
|
|
|
|
|
|
|
|
bool operator<(const BDate& date) const;
|
|
|
|
bool operator<=(const BDate& date) const;
|
|
|
|
|
|
|
|
bool operator>(const BDate& date) const;
|
|
|
|
bool operator>=(const BDate& date) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32 _DaysInMonth(int32 year, int32 month) const;
|
|
|
|
bool _SetDate(int32 year, int32 month, int32 day);
|
|
|
|
int32 _DateToJulianDay(int32 year, int32 month, int32 day) const;
|
|
|
|
|
2007-10-14 17:53:53 +04:00
|
|
|
private:
|
|
|
|
int32 fDay;
|
|
|
|
int32 fYear;
|
|
|
|
int32 fMonth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BDateTime {
|
|
|
|
public:
|
|
|
|
BDateTime(const BDate &date, const BTime &time);
|
|
|
|
~BDateTime();
|
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
static BDateTime CurrentDateTime(time_type type);
|
|
|
|
void SetDateTime(const BDate &date, const BTime &time);
|
|
|
|
|
|
|
|
BDate Date() const;
|
|
|
|
void SetDate(const BDate &date);
|
|
|
|
|
|
|
|
BTime Time() const;
|
|
|
|
void SetTime(const BTime &time);
|
|
|
|
|
|
|
|
uint32 Time_t() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BDate fDate;
|
|
|
|
BTime fTime;
|
|
|
|
};
|
|
|
|
|
2008-08-29 23:26:58 +04:00
|
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
|
2007-10-14 17:53:53 +04:00
|
|
|
#endif // _DATE_TIME_H_
|