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