-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimeStamp.cpp
More file actions
executable file
·132 lines (110 loc) · 2.45 KB
/
Copy pathTimeStamp.cpp
File metadata and controls
executable file
·132 lines (110 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* TimeStamp.cpp
* Klasse fuer die Kapselung eines Zeitstempels.
*
* @mc Arduino/RBBB
* @autor Christian Aschoff / caschoff _AT_ mac _DOT_ com
* @version 1.1
* @datum 2.3.2011
*
* Versionshistorie:
* V 1.1: - Feher in toString() behoben.
*/
#include "TimeStamp.h"
// #define DEBUG
TimeStamp::TimeStamp() {
}
TimeStamp::TimeStamp(MyDCF77 dcf77){
setFrom(dcf77);
}
TimeStamp::TimeStamp(DS1307 ds1307){
setFrom(ds1307);
}
int TimeStamp::getMinutes(){
return _minutes;
}
int TimeStamp::getMinutesOfDay() {
return _minutes + 60 * _hours;
}
int TimeStamp::getHours(){
return _hours;
}
int TimeStamp::getDate(){
return _date;
}
int TimeStamp::getDayOfWeek(){
return _dayOfWeek;
}
int TimeStamp::getMonth(){
return _month;
}
int TimeStamp::getYear(){
return _year;
}
void TimeStamp::setFrom(MyDCF77 dcf77){
_minutes = dcf77.getMinutes();
_hours = dcf77.getHours();
_date = dcf77.getDate();
_dayOfWeek = dcf77.getDayOfWeek();
_month=dcf77.getMonth();
_year=dcf77.getYear();
}
void TimeStamp::setFrom(DS1307 ds1307){
_minutes = ds1307.getMinutes();
_hours = ds1307.getHours();
_date = ds1307.getDate();
_dayOfWeek = ds1307.getDayOfWeek();
_month=ds1307.getMonth();
_year=ds1307.getYear();
}
void TimeStamp::set(int minutes, int hours, int date, int dayOfWeek, int month, int year){
_minutes = minutes;
_hours = hours;
_date = date;
_dayOfWeek = dayOfWeek;
_month = month;
_year = year;
}
/**
* Die Zeit als String bekommen
*/
char* TimeStamp::asString() {
_cDateTime[0] = 0;
char temp[5];
// build the string...
if (_hours < 10) {
sprintf(temp, "0%d:", _hours);
strncat(_cDateTime, temp, strlen(temp));
}
else {
sprintf(temp, "%d:", _hours);
strncat(_cDateTime, temp, strlen(temp));
}
if (_minutes < 10) {
sprintf(temp, "0%d ", _minutes);
strncat(_cDateTime, temp, strlen(temp));
}
else {
sprintf(temp, "%d ", _minutes);
strncat(_cDateTime, temp, strlen(temp));
}
if (_date < 10) {
sprintf(temp, "0%d.", _date);
strncat(_cDateTime, temp, strlen(temp));
}
else {
sprintf(temp, "%d.", _date);
strncat(_cDateTime, temp, strlen(temp));
}
if (_month < 10) {
sprintf(temp, "0%d.", _month);
strncat(_cDateTime, temp, strlen(temp));
}
else {
sprintf(temp, "%d.", _month);
strncat(_cDateTime, temp, strlen(temp));
}
sprintf(temp, "%d", _year);
strncat(_cDateTime, temp, strlen(temp));
return _cDateTime;
}