Medial Code Documentation
Loading...
Searching...
No Matches
MedTime.h
Go to the documentation of this file.
1
9
10#ifndef __MED__TIME__H__
11#define __MED__TIME__H__
12
13#include <vector>
14#include <string>
15using namespace std;
16
19class MedTime {
20
21public:
22
23 // names for timing options
24 const static int Undefined = 0;
25 const static int Date = 1;
26 const static int Years = 2;
27 const static int Months = 3;
28 const static int Days = 4;
29 const static int Hours = 5;
30 const static int Minutes = 6;
31 const static int DateTimeString = 7;
32 const static int MIN_DATE_SUPPORT = 19000000;
33
34 vector<int> YearsMonths2Days;
35 vector<int> Years2Days;
36 vector<int> Days2Years;
37 vector<int> Days2Months;
38 vector<int> Days2Date;
39 vector<int> days2month = { 0,31,59,90,120,151,181,212,243,273,304,334,365 };
40
42
43 bool is_valid_date(int date) const;
44
45 // general converters
46 // when times are given/returned in int they are rounded to the floor
47 // then times are given/returned in double they are in fractions of the given/requested unit
48
56 int convert_times(int from_type, int to_type, int in_time);
57 int convert_times(int from_type, int to_type, double in_time);
58 double convert_times_D(int from_type, int to_type, int in_time);
59 double convert_times_D(int from_type, int to_type, double in_time);
60 string convert_times_S(int from_type, int to_type, int in_time);
64 void init_time_tables();
65
74 int convert_date(int to_type, int in_time);
76 int convert_datetime(int to_type, string in_time);
77
80 int convert_datetime_safe(int to_type, string in_time, char handle_ilegal_date = 2);
81
82 int convert_years(int to_type, int in_time);
83 int convert_months(int to_type, int in_time);
84 int convert_days(int to_type, int in_time);
85 int convert_hours(int to_type, int in_time);
86 int convert_minutes(int to_type, int in_time);
87 int add_subtruct_days(int in_time, int delta_days);
88
90 int string_to_type(const string &str);
91
93 string type_to_string(int type);
94
95 int diff_times(int d1, int d2, int in_type, int out_type);
96 double diff_times_D(int d1, int type1, int d2, int type2, int out_type);
97 int diff_times(int d1, int type1, int d2, int type2, int out_type);
98
99 double get_age(int t, int type_t, int byear);
100 double get_age_from_bdate(int t, int type_t, int bdate);
101
103 int add_subtract_time(int in_time, int in_type, int delta_time, int delta_type);
104};
105
110extern int global_default_time_unit;
111extern int global_default_windows_time_unit;
112
113
114#endif
MedTime med_time_converter
global time converter.
Definition MedTime.cpp:10
The following is a class to handle time conversions There's a global instance of it declared below (m...
Definition MedTime.h:19
int add_subtract_time(int in_time, int in_type, int delta_time, int delta_type)
subtract time (truncating negative values)
Definition MedTime.cpp:457
static const int Minutes
minutes since 1900/01/01
Definition MedTime.h:30
static const int DateTimeString
string only format "YYYYMMDDHHMI"
Definition MedTime.h:31
int convert_datetime(int to_type, string in_time)
converts from YYYYMMDDHHMI format
Definition MedTime.cpp:173
void init_time_tables()
init of time table
Definition MedTime.cpp:39
static const int Undefined
undefined time unit
Definition MedTime.h:24
int convert_datetime_safe(int to_type, string in_time, char handle_ilegal_date=2)
converts from YYYYMMDDHHMI format include warning in dates before 1900 - for loading.
Definition MedTime.cpp:139
int convert_times(int from_type, int to_type, int in_time)
Converts time formats.
Definition MedTime.cpp:284
string type_to_string(int type)
Converts type to string.
Definition MedTime.cpp:368
static const int Days
days since 1900/01/01
Definition MedTime.h:28
static const int MIN_DATE_SUPPORT
minimal date support
Definition MedTime.h:32
static const int Years
years since 1900 (not since 0!)
Definition MedTime.h:26
static const int Hours
hours since 1900/01/01
Definition MedTime.h:29
int string_to_type(const string &str)
Convert string to type.
Definition MedTime.cpp:358
static const int Months
months since 1900/01/01
Definition MedTime.h:27
int convert_date(int to_type, int in_time)
Converts time formats from date format as input.
Definition MedTime.cpp:193
static const int Date
dates are in full regular format YYYYMMDD
Definition MedTime.h:25
Definition StdDeque.h:58