AceTime  0.5.2
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.
LocalDateTime.cpp
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #include "common/util.h"
7 #include "common/DateStrings.h"
8 #include "LocalDateTime.h"
9 
10 namespace ace_time {
11 
12 using common::printPad2;
13 using common::DateStrings;
14 
15 void LocalDateTime::printTo(Print& printer) const {
16  if (isError()) {
17  printer.print(F("<Invalid LocalDateTime>"));
18  return;
19  }
20 
21  // Date
22  printer.print(mLocalDate.year());
23  printer.print('-');
24  printPad2(printer, mLocalDate.month());
25  printer.print('-');
26  printPad2(printer, mLocalDate.day());
27 
28  // 'T' separator
29  printer.print('T');
30 
31  // Time
32  printPad2(printer, mLocalTime.hour());
33  printer.print(':');
34  printPad2(printer, mLocalTime.minute());
35  printer.print(':');
36  printPad2(printer, mLocalTime.second());
37 }
38 
40  if (strlen(dateString) < kDateTimeStringLength) {
41  return LocalDateTime::forError();
42  }
43  return forDateStringChainable(dateString);
44 }
45 
46 
48  const char* s = dateString;
49 
50  // date
52 
53  // 'T'
54  s++;
55 
56  // time
58 
59  dateString = s;
60  return LocalDateTime(ld, lt);
61 }
62 
63 }
64 
The time (hour, minute, second) fields representing the time without regards to the day or the time z...
Definition: LocalTime.h:26
void printTo(Print &printer) const
Print LocalDateTime to &#39;printer&#39; in ISO 8601 format.
static LocalTime forTimeStringChainable(const char *&timeString)
Variant of forTimeString() that updates the pointer to the next unprocessed character.
Definition: LocalTime.cpp:35
static LocalDateTime forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
static LocalDate forDateStringChainable(const char *&dateString)
Variant of forDateString() that updates the pointer to the next unprocessed character.
Definition: LocalDate.cpp:74
uint8_t day() const
Return the day of the month.
Definition: LocalDate.h:237
static LocalDateTime forDateString(const char *dateString)
Factory method.
static LocalDateTime forError()
Factory method that returns an instance where isError() returns true.
uint8_t hour() const
Return the hour.
Definition: LocalTime.h:116
The date (year, month, day) representing the date without regards to time zone.
Definition: LocalDate.h:36
uint8_t minute() const
Return the minute.
Definition: LocalTime.h:122
uint8_t month() const
Return the month with January=1, December=12.
Definition: LocalDate.h:231
int16_t year() const
Return the full year instead of just the last 2 digits.
Definition: LocalDate.h:219
uint8_t second() const
Return the second.
Definition: LocalTime.h:128
LocalDateTime()
Constructor.
bool isError() const
Return true if any component indicates an error condition.
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:27