@@ -17,6 +17,10 @@ in the source distribution for its full text.
1717#include "Object.h"
1818
1919
20+ static const int ClockMeter_attributes [] = {
21+ CLOCK
22+ };
23+
2024static const int DateMeter_attributes [] = {
2125 DATE
2226};
@@ -25,28 +29,42 @@ static const int DateTimeMeter_attributes[] = {
2529 DATETIME
2630};
2731
28- static void DateMeter_updateValues (Meter * this ) {
29- const Machine * host = this -> host ;
30-
31- struct tm result ;
32- const struct tm * lt = localtime_r (& host -> realtime .tv_sec , & result );
33- strftime (this -> txtBuffer , sizeof (this -> txtBuffer ), "%F" , lt );
34- }
35-
3632static void DateTimeMeter_updateValues (Meter * this ) {
3733 const Machine * host = this -> host ;
3834
3935 struct tm result ;
4036 const struct tm * lt = localtime_r (& host -> realtime .tv_sec , & result );
41- strftime (this -> txtBuffer , sizeof (this -> txtBuffer ), "%F %H:%M:%S" , lt );
37+ if (As_Meter (this ) == & ClockMeter_class ) {
38+ strftime (this -> txtBuffer , sizeof (this -> txtBuffer ), "%H:%M:%S" , lt );
39+ } else if (As_Meter (this ) == & DateMeter_class ) {
40+ strftime (this -> txtBuffer , sizeof (this -> txtBuffer ), "%F" , lt );
41+ } else {
42+ strftime (this -> txtBuffer , sizeof (this -> txtBuffer ), "%F %H:%M:%S" , lt );
43+ }
4244}
4345
46+ const MeterClass ClockMeter_class = {
47+ .super = {
48+ .extends = Class (Meter ),
49+ .delete = Meter_delete
50+ },
51+ .updateValues = DateTimeMeter_updateValues ,
52+ .defaultMode = TEXT_METERMODE ,
53+ .supportedModes = (1 << TEXT_METERMODE ) | (1 << LED_METERMODE ),
54+ .maxItems = 0 ,
55+ .total = 0.0 ,
56+ .attributes = ClockMeter_attributes ,
57+ .name = "Clock" ,
58+ .uiName = "Clock" ,
59+ .caption = "Time: " ,
60+ };
61+
4462const MeterClass DateMeter_class = {
4563 .super = {
4664 .extends = Class (Meter ),
4765 .delete = Meter_delete
4866 },
49- .updateValues = DateMeter_updateValues ,
67+ .updateValues = DateTimeMeter_updateValues ,
5068 .defaultMode = TEXT_METERMODE ,
5169 .supportedModes = (1 << TEXT_METERMODE ) | (1 << LED_METERMODE ),
5270 .maxItems = 0 ,
0 commit comments