瀏覽代碼

Adds short timestamp format to timestamp_t

João Brázio 9 年之前
父節點
當前提交
ecd48027fa
共有 1 個文件被更改,包括 31 次插入21 次删除
  1. 31
    21
      Marlin/timestamp_t.h

+ 31
- 21
Marlin/timestamp_t.h 查看文件

30
   uint32_t timestamp;
30
   uint32_t timestamp;
31
 
31
 
32
   /**
32
   /**
33
-   * @brief Date time blank constructor
33
+   * @brief Timestamp blank constructor
34
    */
34
    */
35
   timestamp_t()
35
   timestamp_t()
36
     : timestamp_t(0) {};
36
     : timestamp_t(0) {};
37
 
37
 
38
   /**
38
   /**
39
-   * @brief Date time constructor
39
+   * @briefTimestamp constructor
40
    * @details Initializes the timestamp_t structure based on a number of seconds
40
    * @details Initializes the timestamp_t structure based on a number of seconds
41
    *
41
    *
42
    * @param seconds The number of seconds
42
    * @param seconds The number of seconds
46
   }
46
   }
47
 
47
 
48
   /**
48
   /**
49
-   * @brief Formats the date as number of years
49
+   * @brief Formats the timestamp in years
50
    * @return The number of years
50
    * @return The number of years
51
    */
51
    */
52
   inline uint8_t year() const {
52
   inline uint8_t year() const {
54
   }
54
   }
55
 
55
 
56
   /**
56
   /**
57
-   * @brief Formats the date as number of days
57
+   * @brief Formats the timestamp in days
58
    * @return The number of days
58
    * @return The number of days
59
    */
59
    */
60
   inline uint16_t day() const {
60
   inline uint16_t day() const {
62
   }
62
   }
63
 
63
 
64
   /**
64
   /**
65
-   * @brief Formats the date as number of hours
65
+   * @brief Formats the timestamp in hours
66
    * @return The number of hours
66
    * @return The number of hours
67
    */
67
    */
68
   inline uint32_t hour() const {
68
   inline uint32_t hour() const {
70
   }
70
   }
71
 
71
 
72
   /**
72
   /**
73
-   * @brief Formats the date as number of minutes
73
+   * @brief Formats the timestamp in minutes
74
    * @return The number of minutes
74
    * @return The number of minutes
75
    */
75
    */
76
   inline uint32_t minute() const {
76
   inline uint32_t minute() const {
78
   }
78
   }
79
 
79
 
80
   /**
80
   /**
81
-   * @brief Formats the date as number of seconds
81
+   * @brief Formats the timestamp in seconds
82
    * @return The number of seconds
82
    * @return The number of seconds
83
    */
83
    */
84
   inline uint32_t second() const {
84
   inline uint32_t second() const {
86
   }
86
   }
87
 
87
 
88
   /**
88
   /**
89
-   * @brief Formats the date as a string
89
+   * @brief Formats the timestamp as a string
90
    * @details Returns the timestamp formated as a string
90
    * @details Returns the timestamp formated as a string
91
    *
91
    *
92
-   * @param buffer The array pointed to must be able to accommodate 21 bytes
92
+   * @param buffer The array pointed to must be able to accommodate 21 bytes when
93
+   *               on standard mode or 10 bytes otherwise.
94
+   * @param shorty If true a short representation will be returned.
93
    *
95
    *
94
-   * String output examples:
96
+   * Standard toString() output examples:
95
    *  123456789012345678901 (strlen)
97
    *  123456789012345678901 (strlen)
96
    *  135y 364d 23h 59m 59s
98
    *  135y 364d 23h 59m 59s
97
    *  364d 23h 59m 59s
99
    *  364d 23h 59m 59s
99
    *  59m 59s
101
    *  59m 59s
100
    *  59s
102
    *  59s
101
    *
103
    *
104
+   * Short toString() output examples:
105
+   *  1234567890 (strlen)
106
+   *  1193046:59
107
+   *
102
    */
108
    */
103
-  void toString(char *buffer) const {
104
-    int y = this->year(),
105
-        d = this->day() % 365,
106
-        h = this->hour() % 24,
107
-        m = this->minute() % 60,
108
-        s = this->second() % 60;
109
+  void toString(char *buffer, bool const &shorty = false) const {
110
+    int h = this->hour() % 24,
111
+        m = this->minute() % 60;
112
+
113
+    if (shorty) sprintf_P(buffer, PSTR("%02i:%02i"), h, m);
114
+    else {
115
+      int y = this->year(),
116
+          d = this->day() % 365,
117
+          s = this->second() % 60;
109
 
118
 
110
-    if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
111
-    else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
112
-    else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
113
-    else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
114
-    else sprintf_P(buffer, PSTR("%is"), s);
119
+      if (y) sprintf_P(buffer, PSTR("%iy %id %ih %im %is"), y, d, h, m, s);
120
+      else if (d) sprintf_P(buffer, PSTR("%id %ih %im %is"), d, h, m, s);
121
+      else if (h) sprintf_P(buffer, PSTR("%ih %im %is"), h, m, s);
122
+      else if (m) sprintf_P(buffer, PSTR("%im %is"), m, s);
123
+      else sprintf_P(buffer, PSTR("%is"), s);
124
+    }
115
   }
125
   }
116
 };
126
 };
117
 
127
 

Loading…
取消
儲存