AceTime  0.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
LocalTime.cpp
1 #include "common/util.h"
2 #include "LocalTime.h"
3 
4 namespace ace_time {
5 
6 using common::printPad2;
7 
8 void LocalTime::printTo(Print& printer) const {
9  if (isError()) {
10  printer.print(F("<Invalid LocalTime>"));
11  return;
12  }
13 
14  // Time
15  printPad2(printer, mHour);
16  printer.print(':');
17  printPad2(printer, mMinute);
18  printer.print(':');
19  printPad2(printer, mSecond);
20 }
21 
22 LocalTime LocalTime::forTimeString(const char* timeString) {
23  if (strlen(timeString) < kTimeStringLength) {
24  return forError();
25  }
26  return forTimeStringChainable(timeString);
27 }
28 
29 // This assumes that the dateString is always long enough.
30 LocalTime LocalTime::forTimeStringChainable(const char*& timeString) {
31  const char* s = timeString;
32 
33  // hour
34  uint8_t hour = (*s++ - '0');
35  hour = 10 * hour + (*s++ - '0');
36 
37  // ':'
38  s++;
39 
40  // minute
41  uint8_t minute = (*s++ - '0');
42  minute = 10 * minute + (*s++ - '0');
43 
44  // ':'
45  s++;
46 
47  // second
48  uint8_t second = (*s++ - '0');
49  second = 10 * second + (*s++ - '0');
50 
51  timeString = s;
52  return LocalTime(hour, minute, second);
53 }
54 
55 }
void printTo(Print &printer) const
Print LocalTime to &#39;printer&#39; in ISO 8601 format.
Definition: LocalTime.cpp:8
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
Definition: LocalTime.h:20
static LocalTime forTimeStringChainable(const char *&timeString)
Variant of forTimeString() that updates the pointer to the next unprocessed character.
Definition: LocalTime.cpp:30
bool isError() const
Return true if any component is outside the normal time range of 00:00:00 to 23:59:59.
Definition: LocalTime.h:100
static LocalTime forError()
Factory method that returns an instance which indicates an error condition.
Definition: LocalTime.h:87
uint8_t hour() const
Return the hour.
Definition: LocalTime.h:110
static LocalTime forTimeString(const char *timeString)
Factory method.
Definition: LocalTime.cpp:22
uint8_t minute() const
Return the minute.
Definition: LocalTime.h:116
uint8_t second() const
Return the second.
Definition: LocalTime.h:122
LocalTime()
Default constructor does nothing.
Definition: LocalTime.h:92