mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-03 12:44:27 +02:00
Updated FAQ (markdown)
28
FAQ.md
28
FAQ.md
@@ -1,5 +1,6 @@
|
||||
## Contents
|
||||
- [Why can't I do day arithmetic on a `year_month_day`?](#day_arithmetic)
|
||||
- [Why is `%A` failing?](#week_day_parse_bug)
|
||||
- [Why is `local_t` not a proper clock?](#local_t)
|
||||
|
||||
***
|
||||
@@ -58,6 +59,33 @@ It would be very easy to add `T& list<T>::operator[](size_t index)`. But that w
|
||||
|
||||
This library continues in that tradition: The expensive operations are not hidden.
|
||||
|
||||
<a name="week_day_parse_bug"></a>
|
||||
### Why is `%A` failing?
|
||||
|
||||
This program is supposed to work:
|
||||
|
||||
```c++
|
||||
#include "date/date.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
std::istringstream in{"Sun 2016-12-11"};
|
||||
sys_days tp;
|
||||
in >> parse("%A %F", tp);
|
||||
std::cout << tp << '\n';
|
||||
}
|
||||
```
|
||||
|
||||
But for me it outputs `1970-01-01` and `in.fail()` is true.
|
||||
|
||||
_Answer:_ This is a bug in your std::lib `std::time_get` facet. It _should_ use both `%a` and `%A` identically, and these should both parse either the abbreviated or full `week_day` name in a case-insensitive manner. Unfortunately some implementations won't do that, resulting in this failure. These same implementations have the same bug with `%b` and `%B` (month names).
|
||||
|
||||
You can work around this bug by compiling with `-DONLY_C_LOCALE`. This flag restricts you to the "C" locale, but it also avoids use of your `std::time_get` and `std::time_put` facets, instead implementing that logic within this library.
|
||||
|
||||
<a name="local_t"></a>
|
||||
### Why is `local_t` not a proper clock?
|
||||
|
||||
|
Reference in New Issue
Block a user