Commit Graph

78 Commits

Author SHA1 Message Date
Martchus d8605b50b0 Ensure `chars_format` is defined for older versions of libstdc++
Versions older than 10 don't even define this enum class. Note that libc++
always seems to define it even though it doesn't implement the FP overloads
at all at this point.

By the way, this means the minimum GCC version is 8 and the minimum libc++
version is 7 because for this code to work the `charconv` header still
needs to be present at all.
2023-12-11 19:59:46 +01:00
Martchus 1264a7e9c5 Remove no longer used include in `chrono/timespan.cpp` 2023-12-08 16:24:04 +01:00
Martchus b8dff49c01 Add missing include for `std::array`
See https://github.com/Martchus/cpp-utilities/issues/29
2023-12-07 10:44:27 +01:00
Martchus dd0ea1d348 Use workaround for unavailable `std::from_chars()` also under older libstdc++ versions 2023-12-06 22:34:33 +01:00
Martchus fbb1d73779 Apply clang-format 2023-12-05 11:42:26 +01:00
Martchus 55146db7e1 Add workaround for missing FP overload for `std::from_chars()` in libc++ 2023-11-25 23:18:30 +01:00
Martchus fdfe8f154c Fix warnings in code of `TimeSpan::fromString()` 2023-11-25 23:15:29 +01:00
Martchus 7bed9cd38c Remove TODOs about parsing/printing custom formats
It makes likely more sense to implement that entirely in user code. The
parsing/printing functions for common formats have also been improved so
this is likely not very relevant anymore anyways.
2023-11-23 20:24:44 +01:00
Martchus 11de58141b Support units in `TimeSpan::fromString()` 2023-11-23 20:20:07 +01:00
Martchus a425363eac Improve `TimeSpan::fromString()`
* Avoid heap allocation and counting separators
* Avoid code repetition
* Throw an exception if too many parts are present (as the documentation
  suggests this function would do)
* Allow emptry separators as this seems useful
2023-11-23 18:48:48 +01:00
Martchus 42db96705e Add formatting for `DateTimeExpression` 2022-08-13 14:41:24 +02:00
Martchus 5acf422f71 Add useful operators to `DateTimeExpression`
* Add serialization back to string, useful for implementing
  `TagValue::toString()`
* Add equality comparition
2022-08-13 14:10:40 +02:00
Martchus 4911d16129 Add useful shorthands to `DateTimeParts` 2022-08-13 14:08:46 +02:00
Martchus 3a06641bb9 Improve docs for `DateTimeExpression` 2022-08-13 14:07:57 +02:00
Martchus 5fe03c23a2 Rename `DateTimeParts::Millisecond` to `…::SubSecond`
We're currently just tracking whether the second has a fraction so this is
more fitting.
2022-08-13 14:07:37 +02:00
Martchus f20d596785 Add `DateTimeExpression` to keep track of parsed timestamp parts
The existing timestamp parsers already internally keep track what parts
have been parsed via an index variable. This change exposes this
information as it can sometimes be useful to know what parts were actually
present in the timestamp.
2022-08-12 20:45:06 +02:00
Martchus 77c353fb6c Add `TickType` and integer overloads to chrono utilities 2022-02-15 23:01:25 +01:00
Martchus 6c7e8ae735 Avoid warning about out of bounds array access 2021-12-11 23:58:51 +01:00
Martchus b3ebe5ce38 Fix typos found via `codespell --skip .git -w` 2021-07-03 19:07:49 +02:00
Martchus e6e7a63d6a Make DateTime::fromString() cope with 'T' separator 2021-05-24 21:27:47 +02:00
Martchus a116c9e790 Avoid possibility of overflow in DateTime parsing functions
* This is strictly undefined behavior so let's avoid it
* As a side-effect it is now possible to omit the separators in
  DateTime::fromIsoString()
2021-05-24 21:27:18 +02:00
Martchus 546b1fecb7 Fix parsing ISO timestamp with negative timezone offset and no seconds fraction
See https://github.com/Martchus/syncthingtray/issues/93
2021-05-21 19:40:37 +02:00
Martchus 8c033ca243 Fix warnings 2021-03-20 21:56:45 +01:00
Martchus e6f4bf3561 Apply clang-format 2020-10-31 20:31:04 +01:00
Martchus 1f4fabcd9f Add operators '*' and '/' to TimeSpan 2020-10-24 22:10:25 +02:00
Martchus 32780ed6a6 Support formatting ISO timestamps via DateTime::toString() with option to omit defaults
Omitting components are also allowed when parsing ISO timestamps so it makes sense to
have something similar in the other direction as well.

Note that the idea comes from ID3v2.4.0 which stores timestamps in a subset of ISO 8601
similarily to what this library supports and it allows to omit default components as
well.
2020-04-26 21:38:02 +02:00
Martchus c834f8923d Allow omitting month and day when parsing ISO date
This leaves only the year as mandatory component (other components
can already be omitted).
2020-04-24 22:15:49 +02:00
Martchus 73470d0b65 Fix DateTime::fromDateAndTime() for the day 0001-01-01 2020-04-24 21:55:45 +02:00
Martchus 34170b83f1 Apply clang-format 2020-04-13 01:10:33 +02:00
Martchus 4b67736adf Add DateTime::toIsoStringWithCustomDelimiters() 2020-04-11 21:51:52 +02:00
Martchus 0f56d25251 Use consistent order for visibility attribute 2020-01-29 18:30:02 +01:00
Martchus 085ec2feca Improve DateTime
* Improve documentation about time zone handling
* Add DateTime::toTimeStamp()
* Add experimental DateTime::fromChronoTimePoint()
  and DateTime::fromChronoTimePointGmt()
2019-11-17 22:30:51 +01:00
Martchus 5c098df8d7 Fill last gaps in class list documentation 2019-09-04 18:54:48 +02:00
Martchus 0feb7d667e Add inline/constexpr to more functions in chrono lib 2019-08-19 19:09:19 +02:00
Martchus b48b2f5c06 Have everything in one top-level namespace 2019-06-10 21:56:46 +02:00
Martchus 9a50d2b8df Remove types 2019-04-13 20:33:39 +02:00
Martchus e79563569a Improve Period class 2019-04-13 20:33:39 +02:00
Martchus 8b919250e3 chrono utils: Make public constants signed 2019-04-13 20:33:39 +02:00
Martchus 98edb5a67c Allow omitting second fraction in DateTime::fromIsoString 2018-11-01 20:20:32 +01:00
Martchus 7b01938ece Add {TimeSpan,DateTime}::ticks() for easier read/write 2018-06-23 14:32:46 +02:00
Martchus 2862c81a23 Fix ISO date string parsing/formatting 2018-01-29 16:24:39 +01:00
Martchus 400e73005a Fix use of std::time 2018-01-28 18:03:58 +01:00
Martchus db006408b7 Export DateTime operator+(DateTime begin, Period period) 2017-12-03 14:56:34 +01:00
Martchus 46e9d4b1e4 Add formatting for Period class 2017-12-03 14:55:49 +01:00
Martchus 26cd303422 Improve period compution 2017-12-03 01:45:54 +01:00
Martchus a89f6f9ce4 Improve documentation of chrono library 2017-12-03 01:45:11 +01:00
Martchus 85f29adb8a Use full precision for total seconds in TimeSpan::toString 2017-11-29 23:11:26 +01:00
Martchus d7185fc1bc Improve documentation 2017-11-29 19:11:01 +01:00
Martchus 1ab9349eaa Improve const correctness 2017-11-29 19:08:22 +01:00
Martchus 3051675bbe Allow conversion of TimeSpan to string with total seconds 2017-11-27 10:25:41 +01:00