1 /* 2 Qalculate 3 4 Copyright (C) 2018 Hanna Knutsson (hanna.knutsson@protonmail.com) 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 */ 11 12 #ifndef QALCULATE_DATE_TIME_H 13 #define QALCULATE_DATE_TIME_H 14 15 #include "Number.h" 16 #include "includes.h" 17 18 class QalculateDateTime { 19 protected: 20 long int i_year; 21 long int i_month; 22 long int i_day; 23 long int i_hour; 24 long int i_min; 25 Number n_sec; 26 bool b_time; 27 public: 28 QalculateDateTime(); 29 QalculateDateTime(long int initialyear, int initialmonth, int initialday); 30 QalculateDateTime(const Number &initialtimestamp); 31 QalculateDateTime(std::string date_string); 32 QalculateDateTime(const QalculateDateTime &date); 33 bool operator > (const QalculateDateTime &date2) const; 34 bool operator < (const QalculateDateTime &date2) const; 35 bool operator >= (const QalculateDateTime &date2) const; 36 bool operator <= (const QalculateDateTime &date2) const; 37 bool operator != (const QalculateDateTime &date2) const; 38 bool operator == (const QalculateDateTime &date2) const; 39 bool isFutureDate() const; 40 bool isPastDate() const; 41 void setToCurrentDate(); 42 void setToCurrentTime(); 43 bool set(long int newyear, int newmonth, int newday); 44 bool set(const Number &newtimestamp); 45 bool set(std::string date_string); 46 void set(const QalculateDateTime &date); 47 std::string toISOString() const; 48 std::string toLocalString() const; 49 std::string print(const PrintOptions &po = default_print_options) const; 50 long int year() const; 51 long int month() const; 52 long int day() const; 53 long int hour() const; 54 long int minute() const; 55 const Number &second() const; 56 void setYear(long int newyear); 57 bool setTime(long int ihour, long int imin, const Number &nsec); 58 bool timeIsSet() const; 59 bool addDays(const Number &ndays); 60 bool addMonths(const Number &nmonths); 61 bool addYears(const Number &nyears); 62 bool addHours(const Number &nhours); 63 bool addMinutes(const Number &nminutes, bool remove_leap_second = true, bool convert_to_utc = true); 64 bool addSeconds(const Number &seconds, bool count_leap_seconds = true, bool convert_to_utc = true); 65 bool add(const QalculateDateTime &date); 66 int weekday() const; 67 int week(bool start_sunday = false) const; 68 int yearday() const; 69 Number timestamp(bool reverse_utc = false) const; 70 Number secondsTo(const QalculateDateTime &date, bool count_leap_seconds = true, bool convert_to_utc = true) const; 71 Number daysTo(const QalculateDateTime &date, int basis = 1, bool date_func = true, bool remove_leap_seconds = true) const; 72 Number yearsTo(const QalculateDateTime &date, int basis = 1, bool date_func = true, bool remove_leap_seconds = true) const; 73 74 std::string parsed_string; 75 }; 76 77 typedef enum { 78 CALENDAR_GREGORIAN, 79 CALENDAR_MILANKOVIC, 80 CALENDAR_JULIAN, 81 CALENDAR_ISLAMIC, 82 CALENDAR_HEBREW, 83 CALENDAR_EGYPTIAN, 84 CALENDAR_PERSIAN, 85 CALENDAR_COPTIC, 86 CALENDAR_ETHIOPIAN, 87 CALENDAR_INDIAN, 88 CALENDAR_CHINESE 89 } CalendarSystem; 90 91 #define NUMBER_OF_CALENDARS 11 92 93 #define VERNAL_EQUINOX 0 94 #define SUMMER_SOLSTICE 90 95 #define AUTUMNAL_EXUINOX 180 96 #define WINTER_SOLSTICE 270 97 98 Number solarLongitude(const QalculateDateTime &date); 99 QalculateDateTime findNextSolarLongitude(const QalculateDateTime &date, Number longitude); 100 Number lunarPhase(const QalculateDateTime &date); 101 QalculateDateTime findNextLunarPhase(const QalculateDateTime &date, Number phase); 102 103 bool calendarToDate(QalculateDateTime &date, long int y, long int m, long int d, CalendarSystem ct); 104 bool dateToCalendar(const QalculateDateTime &date, long int &y, long int &m, long int &d, CalendarSystem ct); 105 int numberOfMonths(CalendarSystem ct); 106 std::string monthName(long int month, CalendarSystem ct, bool append_number = false, bool append_leap = true); 107 void chineseYearInfo(long int year, long int &cycle, long int &year_in_cycle, long int &stem, long int &branch); //epoch of 2697 BC 108 long int chineseCycleYearToYear(long int cycle, long int year_in_cycle); 109 int chineseStemBranchToCycleYear(long int stem, long int branch); 110 std::string chineseStemName(long int stem); 111 std::string chineseBranchName(long int branch); 112 113 #endif 114 115