1 /* 2 * Copyright (c) 2015-2021, The OSKAR Developers. 3 * See the LICENSE file at the top-level directory of this distribution. 4 */ 5 6 #ifndef OSKAR_SETTINGS_TYPE_DATETIME_H_ 7 #define OSKAR_SETTINGS_TYPE_DATETIME_H_ 8 9 /** 10 * @file oskar_DateTime.h 11 */ 12 13 #include "settings/types/oskar_AbstractSettingsType.h" 14 15 namespace oskar { 16 17 /** 18 * @class DateTime 19 * 20 * @brief 21 * 22 * @details 23 * TODO check leading zero behaviour in OSKAR ... 24 * oskar_settings_load_observation.cpp 25 * 26 * TODO also ready MJD 27 * 28 * d-M-yyyy h:m:s[.z] - British style 29 * yyyy/M/d/h:m:s[.z] - CASA style 30 * yyyy-M-d h:m:s[.z] - International style 31 * yyyy-M-dTh:m:s[.z] - ISO date style 32 */ 33 class DateTime : public AbstractSettingsType 34 { 35 public: 36 enum Format { UNDEF = -1, BRITISH, CASA, INTERNATIONAL, ISO, MJD }; 37 struct OSKAR_SETTINGS_EXPORT Value 38 { 39 DateTime::Format style; 40 int year, month, day, hours, minutes; 41 double seconds; 42 ValueValue43 Value() : style(DateTime::UNDEF), year(0), month(0), day(0), 44 hours(0), minutes(0), seconds(0.0) {} clearValue45 void clear() 46 { 47 style = DateTime::UNDEF; 48 year = 0; 49 month = 0; 50 day = 0; 51 hours = 0; 52 minutes = 0; 53 seconds = 0.0; 54 } 55 }; 56 57 public: 58 OSKAR_SETTINGS_EXPORT DateTime(); 59 OSKAR_SETTINGS_EXPORT virtual ~DateTime(); 60 61 OSKAR_SETTINGS_EXPORT bool init(const char* s); 62 OSKAR_SETTINGS_EXPORT bool set_default(const char* value); 63 OSKAR_SETTINGS_EXPORT bool set_value(const char* value); 64 OSKAR_SETTINGS_EXPORT bool is_default() const; 65 66 OSKAR_SETTINGS_EXPORT Value value() const; 67 OSKAR_SETTINGS_EXPORT Value default_value() const; 68 69 OSKAR_SETTINGS_EXPORT double to_mjd() const; 70 OSKAR_SETTINGS_EXPORT double to_mjd_2() const; 71 OSKAR_SETTINGS_EXPORT void from_mjd(double mjd); 72 OSKAR_SETTINGS_EXPORT DateTime::Format format() const; 73 74 OSKAR_SETTINGS_EXPORT bool operator==(const DateTime& other) const; 75 OSKAR_SETTINGS_EXPORT bool operator>(const DateTime& other) const; 76 77 private: 78 Value default_, value_; 79 }; 80 81 } /* namespace oskar */ 82 83 #endif /* include guard */ 84