102 Commits

Author SHA1 Message Date
Howard Hinnant
8a563041fa Adjust HAS_STRING_VIEW for VS
Fixes #330
2019-04-05 09:19:54 -04:00
Howard Hinnant
9dc96fd9b5 Silence warning
Fixes #337
2019-03-26 18:13:39 -04:00
Howard Hinnant
8b69087d35 Fix up constexpr of changed weekday_from_days 2019-03-21 12:23:38 -04:00
Howard Hinnant
d5e96f0991 Suppress VS-15 warning about concerning conditional expression is constant
Thanks to https://github.com/ujos for the report.
2019-03-20 21:24:01 -04:00
Evgen Bodunov
5ba1c1ad85 HAS_UNCAUGHT_EXCEPTIONS definition.
Added some flexibility for usage of std::uncaught_exceptions().
Xcode 10 uses clang and perfectly compiles C++17, but
std::uncaught_exceptions() is available only on iOS 10+ devices. When
application supports iOS 9 devices and uses C++17 there is no way to
build it, except drop iOS 9 support or remove C++17 code. Using this
define we could configure should date.h use std::uncaught_exceptions()
or not.
2019-03-20 20:43:43 -04:00
Howard Hinnant
cb7ca96f68 Protect weekday_from_days from signed overflow
Found by static analyzer.
This change makes weekday_from_days slightly more efficient.
2019-03-19 19:51:32 -04:00
Howard Hinnant
b5d025ea2f Align time_of_day with hh_mm_ss
Per committee review
2019-03-19 19:50:30 -04:00
Howard Hinnant
f782ae98f0 Fix type-o again 2019-02-20 15:27:44 -10:00
Howard Hinnant
d6c5d02068 Fix type-o in get_leap_second_info_t 2019-02-20 15:25:50 -10:00
Howard Hinnant
16077472af Rename is_leap_second to get_leap_second_info 2019-02-20 15:19:54 -10:00
Howard Hinnant
5a62c405e0 Remove unneeded make_precision 2019-02-03 23:21:36 -05:00
Howard Hinnant
09a19a09f4 Further consolidate time_of_day logic
Adjust how it works for floating point durations.
2019-02-03 16:14:56 -05:00
Howard Hinnant
9cb0013aef Update time_of_day to be more consistent ...
the needs of formatting.
2019-02-02 14:06:12 -05:00
NeroBurner
4e7e76b981 add c_encoding and iso_encoding weekday functions (#380)
- c_encoding satisfies ctime wday encoding: days since Sunday, range
  [0,6]
- iso_encoding satisfies ISO 8601 weekday:
  a digit d from 1 through 7, beginning with Monday and ending with Sunday
2019-01-19 14:46:21 -05:00
Howard Hinnant
90d0440884 Introduce %q and %Q to_stream formatting flags
* These flags format a duration.
* %Q specifies the duration's numeric value.
* %q specifies the duration's SI abbreviation.
* Example: format("%Q %q", 45ms) == "45 ms"
2019-01-19 14:30:19 -05:00
Daniela Engert
7231a182a4 Revert 5f34c40 and 23b1f00 in preparation of a better solution.
Signed-off-by: Daniela Engert <dani@ngrt.de>
2018-12-16 15:29:17 -05:00
Howard Hinnant
5f34c40523 More patches for VS-2017 compatiblity 2018-11-25 17:04:27 -05:00
Howard Hinnant
23b1f007fe Patch for VS-2017 compatiblity 2018-11-25 14:38:54 -05:00
Howard Hinnant
a22125ca40 Remove constexpr from islamic::year::isleap for C++11 2018-11-20 09:00:12 -05:00
Howard Hinnant
8f91ef27ed Revert "Model the TAI-UTC difference between 1961 and 1972"
This reverts commit 1eed461d06b02854d9310d5ab0198eccd2be1d1d.
2018-11-08 13:56:23 -08:00
Howard Hinnant
1eed461d06 Model the TAI-UTC difference between 1961 and 1972 2018-10-03 17:51:55 -04:00
Howard Hinnant
591f572b67 Allow %j to parse and format durations 2018-09-26 14:35:03 -07:00
F
69e9cd612f Prefer using std::string that using namespace std and unqualified string (#386)
'using namespace std;' in header files can conflict with custom
namespace names. For example 'string' is used without 'std::'
qualification. If tz.h is included in a file where string is a
namespace, it cannot be compiled anymore. The same happens with date.h
if ONLY_C_LOCALE=1.
2018-09-26 17:31:56 -04:00
Howard Hinnant
6a4d93a0bd Silence more shadow warnings 2018-07-01 23:00:33 -04:00
Howard Hinnant
39d6730665 Silence shadow warnings 2018-07-01 22:37:25 -04:00
Howard Hinnant
de6a03d337 Set _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING for VS 2018-06-27 09:21:19 -04:00
Jaka Bac
1b32e316db Workaround MSVC 19.14.26431 parsing bug (#355) 2018-06-21 10:08:59 -04:00
tomaszkam
f46885e632 Suffix d for days duration (#354) 2018-06-20 11:39:48 -04:00
Tomasz Kamiński
2d282e35fa Use string_literal for C++11 when possible 2018-06-19 19:37:02 -04:00
Howard Hinnant
d50970b32a Some backwards compatibility fixes for VS-2013 2018-06-12 18:13:24 -04:00
Christopher Blaesius
07876e4433 Character classification functions (isspace, isalnum) are undefined for signed chars
Convert them to int using char_traits or static_cast to unsigned char
2018-06-11 17:00:45 -04:00
Howard Hinnant
0197889505 Update to Sunday constants 2018-06-11 15:14:44 -04:00
Tomasz Kamiński
db60c5eb8e Unit test and typo fix 2018-06-11 10:45:41 -04:00
Tomasz Kamiński
9f1c4b0110 Implemented clock_cast for local_time.
Implemented clock_time_conversion<D, local_t> calling D::from_local
and clock_time_conversion<locat_t, S> calling S::to_local.

To avoid ambiguities addes:
* clock_time_conversion<local_t, local_t> - idenitity
* clock_time_conversion<local_t, utc_clock> - same as default (utc_clock::to_local)
* clock_time_conversion<utc_clock, local_t> - same as default (utc_clock::from_local)

In addition, as std::chrono::system_clock cannot be edited, added:
* clock_time_conversion<local_t, std::chrono::system_clock> - assumes same epoch
* clock_time_conversion<std::chrono::system_clock, local_t> - assumes same epoch
They will be required to resolve amibiguity anyway.
2018-06-11 10:45:41 -04:00
Tomasz Kamiński
da15227f6c Implemented to/from_local functions for utc/tai/gps.
Implemented to_local and from_local functions for utc_clock,
tai_clock and gps_clock. For the tai/gps clock used this function
for defining the io - we delegate to serializing/parsing local
time.

The drwaback is that the local_time cannot properly represent
leap second in the UTC time, so separate serialization is needed.
2018-06-11 10:45:41 -04:00
Howard Hinnant
d4fb7eb76d Put unspecified_month_disambiguator in namespace detail 2018-06-10 16:22:21 -04:00
Tomasz Kamiński
0e3e84fd56 Used suggested Tim Song implementation 2018-06-10 16:22:21 -04:00
Tomasz Kamiński
3eac2d376e Revert "Fixed addition of multi-year duration to year_month."
This reverts commit 328cecaa567e8b9da5dfcbcb4de9a550496bb55b.
2018-06-10 16:22:21 -04:00
Howard Hinnant
f5f4d76936 Replace save_stream with save_ostream
* In islamic.h and julian.h
2018-06-10 15:44:43 -04:00
Howard Hinnant
c7b69d949a Change the encoding for an invalid weekday from 7 to 8 2018-06-08 09:50:40 -04:00
Howard Hinnant
48baa942fc Use uncaught_exceptions in C++17 2018-06-06 13:52:23 -04:00
Howard Hinnant
be2ec2310b Emphasize Sunday over sun in the implementation
*  Keep the three letter lower case spellings for backwards
   compatibility purposes.
2018-06-03 13:55:00 -04:00
Howard Hinnant
40b83654b6 [API BREAKING] Remove conversion from weekday to unsigned
* There has been a great deal of anguish over the encoding of
  weekdays:  whether [0, 6] maps to [Sunday, Saturday] or
  [1, 7] maps to [Monday, Sunday].  This commit attempts
  to address that issue, but will break a small amount of
  code at compile-time.  See below on how to fix that.

* The weekday constructor used to accept [0, 6] to represent
  [Sunday, Saturday].  It now accepts [0, 7] to represent
  [Sunday, Saturday] with both 0 and 7 mapping to Sunday.

* The conversion from weekday to unsigned has been removed.

* To convert a weekday to unsigned replace:

      auto u = unsigned{wd};

  with:

      auto u = (wd - Sunday).count();

  This maps [Sunday, Saturday] to [0, 6], which is the
  C/POSIX mapping.  If you prefer the ISO mapping
  ([Monday, Sunday] -> [1, 7]), then do:

      auto u = (wd - Monday).count() + 1;
2018-06-02 22:56:10 -04:00
Eugene Golushkov
1fdda81a30 fixed build with latest VS2017 v15.7.1; toolset MSVC 14.14 2018-06-02 16:14:18 -04:00
apo
f33e179936 Eliminate use of uninitialized offset. 2018-05-25 09:56:34 -04:00
Tomasz Kamiński
328cecaa56 Fixed addition of multi-year duration to year_month.
* Added new overloads for operator+/- between year_month and duration
  that is convertible to years, so it is better candidate for operands
  that are convertible to both years and months. To preserve
  functionality, this operator is conditionally noexcept.

* Reworked year_month_day, year_month_day_last, year_month_weekday,
  and year_month_weekday_last.

* Added tests for this new functionality.
2018-05-12 18:21:24 -04:00
Howard Hinnant
5d15157bbb Fix bug for parsing negative offsets of less than 1h 2018-05-05 12:01:56 -04:00
Howard Hinnant
a91ceefb4e Allow %H %M and %S to deal with negative durations 2018-04-23 20:31:28 -04:00
Howard Hinnant
88c661e9f3 Fix zoned_time deduction guides 2018-04-23 20:30:58 -04:00
Howard Hinnant
c665992a6e Allow heterogeneous zoned_time constructors
taking {string_view, zoned_time}
2018-04-21 17:45:52 -04:00
Howard Hinnant
9d0bcdb63f Fix deduction error in parse where only offset is requested 2018-04-18 21:56:11 -04:00
Howard Hinnant
973bd393bc Respect and minimize tie/flush in from/to_stream
* Save/restore tie, setting it to nullptr during the operation
* On construction tie_->flush()
* For ostreams only, flush if unitbuf
2018-04-18 21:47:15 -04:00
Howard Hinnant
d53db7a1cb And yet more fixes to allow duplicate flags on parse 2018-04-15 15:32:24 -04:00
Howard Hinnant
e5c69d84ab Fix constexpr issue for VS2015 2018-04-09 11:01:58 -04:00
Howard Hinnant
b48a18a1d9 More fixes to allow duplicate parsing 2018-04-08 15:49:06 -04:00
Howard Hinnant
cdb4b276d9 Allow duplicate parsing into the same fields
* as long as all duplicates produce consistent results.
2018-04-07 21:42:00 -04:00
Howard Hinnant
1d9e49ea21 to_stream sets failbit if unable to format
*  If a formatting flag requests data that is not available in
   the Streamable object, or if the Streamable object answers !ok(),
   failbit is set.
2018-04-06 11:19:44 -04:00
Howard Hinnant
0125d330ab Correct to_stream/from_stream handling of stream data
* to_stream and from_stream now reset the stream formatting state to
  default settings on entry, and restore the stream state on exit.

* to_stream and from_stream now correctly handle mis-modified flags.

* Fix %h to be equivalent to %b instead of %B.

* This addresses issues 319, 320 and 321.
2018-03-31 13:06:57 -04:00
Howard Hinnant
700489e475 Introduced full weekday and month names
* The standardized version of this library has std::chrono::January
  and std::chrono::Sunday in place of std::chrono_literals::jan and
  std::chrono_literals::sun.  Compatible names added to namespace
  date to ease transition from this lib to std::chrono.  The old
  names are retained for backwards compatibility.
2018-03-18 18:27:04 -04:00
Howard Hinnant
1e8ab50f82 Test modifications for standardization 2018-03-14 22:49:04 -04:00
Howard Hinnant
0bde4ba8c8 Make the parsing of minutes optional under the flag %z 2018-03-03 11:57:03 -05:00
Howard Hinnant
43d8a4eab0 Range check minutes under parse 2018-03-02 09:03:41 -05:00
mwu
ca4036a4b0 Explicitly qualify std::string. Having a global scope string type shall not break the compilation anymore. 2018-02-23 21:17:26 -05:00
Alexander Karatarakis
a1ceec19fe Workaround for MSVC 2018-02-20 11:51:28 -05:00
Benno Evers
2acf403bcd Dont include ios.h unconditionally.
The include in tz.cpp was changed to only include the ios.h header
when compiling on apple platforms, as the documentation states that
only the four files date.h, tz.h, tz_private.h, and tz.cpp should be
required to use the time zone library.

Additionally, the ios.mm file was moved to src/ since it contains
C++ source code.
2018-01-24 20:24:10 -05:00
Howard Hinnant
3b8372f4fa Avoid use of undeclared to_utc_time.
* Fixes https://github.com/HowardHinnant/date/issues/289
2018-01-18 15:55:58 -05:00
Xuesong Hu
6941691de4 implement current_zone() for iOS using native API from iOSUtils 2018-01-12 14:59:01 -05:00
Michael Maroszek
09b78ba92c bump msvc define to fix compile issue on MSVC 15.6 2018-01-12 10:51:05 -05:00
Scott Beil
2b6ee6378c minutes fix 2018-01-05 18:42:48 -05:00
Howard Hinnant
b49bdc3ca7 Add missing include <memory> for unique_ptr 2017-12-06 10:12:49 -05:00
Howard Hinnant
c7e5a4d08e Add posix-style time zone example: ptz.h 2017-12-03 14:40:01 -05:00
Howard Hinnant
a3e8f399c4 ifdef out clock_cast for VC-2017 and earlier
* Clients report it can't handle the C++11
* Triggered to be enabled on VC-number-next
* Deprecated API (to_xxx_time) rewritten to be independent of
  clock_cast.
* Whitespace changes to bring column length down to 90.
2017-11-30 15:40:37 -05:00
Howard Hinnant
443a29df53 Improve range check on year
* The previous fix broke parsing of sub-date quantities such as
  durations.
2017-11-30 12:06:51 -05:00
Howard Hinnant
1902b8e8fb Range check year on parse 2017-11-30 10:45:30 -05:00
Howard Hinnant
c513a20691 Fix off-by-one bug in iso_week::year_lastweek_weekday
* The conversion from year_lastweek_weekday to sys_days
  and local_days had an off by one error.
* Added test for this case.
2017-11-30 10:28:14 -05:00
Howard Hinnant
9b88763dbf Remove noexcept from tai_clock::now() and gps_clock::now()
*  These functions may try to initialize the tzdb which
   could fail.
2017-11-26 21:24:45 -05:00
Howard Hinnant
15a63ec819 Updated on behalf of schmidt9 2017-11-26 14:41:40 -05:00
Tomasz Kamiński
543315b700 Reversed order of arguments to clock_time_conversion.
Now the order of argument matches the clock_cast function.
The test only is_clock_castable trait still matches is_convertible
order of arguments.
2017-11-26 13:50:21 -05:00
Tomasz Kamiński
7c69f1570d Changed invocation to match specification
Slight difference between invocation on lvalue of clock_time_conversion
object and prvalue.
2017-11-25 22:01:12 +01:00
Tomasz Kamiński
b13c859ff1 Restored deprecated to_clock_time function.
Fixed the to_utc_time(const gps_time<Duration>& t) function
to correctly use clock_cast<utc_time>.

Added test to deprecated functions.
2017-11-24 23:37:32 +01:00
Tomasz Kamiński
d4592bd497 Maked clock_time_conversion as const and used alias.
Marked operator() of all supplied clock_time_conversion overload
as const.
Changed input type to sys_time/utc_time alias when possible.
Used consitient nomencalture: st for sys_time, ut for utc_time
and tp for time in different clock.
2017-11-24 23:26:56 +01:00
Tomasz Kamiński
58a4a9518a Mismatch in return type of converting function is now hard error.
Change the implementation, in the way that mismatch in return
type of the from/to_sys/utc functions (not returning time_point,
or returning time_point with inappropriate clock) leads to
hard error.

Added appropariate fail test for to_sys function, including:
* returning an int
* returning time_point of wrong clock
* reutrning reference to time_point
2017-11-24 22:23:50 +01:00
Tomasz Kamiński
e1099ef3ab Implemented clock_cast function.
Added an clock_time_conversion trait, that should be specialized
with SourceClock and DestClock respectively and provide an function
that convert time_point in SourceClock to equivalent time_point
in DestClock.

This function has following specializations:
1) <sys_clock, utc_clock> - convert sys_time to utc_time
2) <utc_clock, sys_clock> - convert utc_time to sys_time
3) <Clock, sys_clock>     - calls Clock::to_sys if it returns sys_time
4) <Clock, utc_clock>     - calls Clock::to_utc if it returns utc_time
5) <sys_clock, Clock>     - calls Clock::from_sys if it returns time_point<Clock>
5) <utc_clock, Clock>     - calls Clock::from_utc if it returns time_point<Clock>

Implemented an clock_cast<DestClock>(time_point<SourceClock, Dur> st), that
works as follow:
1) If DestClock is same as SourceClock, returns std
2) Otherwise, if clock_conversion<SourceClock, DestClock> available, uses it
3) Otherwise, if tries using clock_conversion<SourceClock, CommClock>
   and clock_conversion<CommClock, DestClock> for CommClock being utc_time
   or sys_time
4) Otherwise, tries using clock_conversion<SourceClock, utc_clock>
   and clock_conversion<sys_clock, DestinationClock> or reversed (firstly
   convert to sys_clock, then to utc_clock) to convert.
2017-11-24 17:55:15 +01:00
Howard Hinnant
c286981b3b Fix improper application of GCC diagnostic suppression 2017-11-21 10:07:31 -05:00
Howard Hinnant
9ca582d9da Silence GCC conversion warning for bitfields
* Used only in weekday_indexed.
2017-11-20 14:50:48 -05:00
Tullio Menga
f4b12ab023 Adjust HAS_CHRONO_ROUNDING macro for MSVC with v140_clang_c2 and LLVM-vs2014 2017-11-20 11:45:04 -05:00
Alexander Karatarakis
bd51baf31e msvc token workaround 2017-11-19 18:52:56 -05:00
Howard Hinnant
d97bc984c7 Change default_zone from "UTC" to "Etc/UTC"
* zoned_traits<const time_zone*>::default_zone()
  should not depend on a Link, but on a Zone.
2017-11-19 18:17:09 -05:00
Howard Hinnant
4832ea0ddb Move HAS_STRING_VIEW to date.h 2017-11-17 11:09:17 -05:00
Tullio Menga
ec514101a6 minor patches to build on Windows with MSVC v140_clang_c2 and LLVM-vs2014 2017-11-15 07:20:07 -05:00
Howard Hinnant
e12f7c66f0 Unconstrain make_zoned for VS-2015 2017-11-07 13:01:16 -07:00
Howard Hinnant
3a5e8c9384 Silence clang warning 2017-10-30 13:48:09 -04:00
Howard Hinnant
fa6529a2fc Allow zoned_time conversion among different TimeZonePtr types 2017-10-28 18:20:34 -04:00
Howard Hinnant
25696b7fb3 Optimize to_stream for zoned_time
* Decrease the number of lookups in the database from 2 to 1.
2017-10-24 15:44:41 -04:00
Howard Hinnant
9381e894a5 Specify exception constructors
* For nonexistent_local_time and ambiguous_local_time.
* Simplify the constructors.
* Make these exceptions usable for custom time zones.
2017-10-24 12:12:31 -04:00
Pavel Davydov
202041e531 Add a workaround for a missing operator<< for gcc 5 on linux. See issue #205 for details. 2017-10-24 11:02:54 -04:00
Howard Hinnant
66a97f907e to_stream sets failbit if required to supply a bad name:
* for an invalid month
* for an invalid weekday
2017-10-15 13:57:19 -04:00
Howard Hinnant
f328d8c84a Have format set exceptions(failbit | badbit)
*  Be sure if something bad happens under the hood it is not silently
   swallowed.
2017-10-14 20:42:26 -04:00
Manlio Morini
8b9f0515b5 Replacing 0 with nullptr to avoid GCC warning
All the calls to `std::time_get::get` had `0` as end-of-range iterator.

E.g.

    auto& f = use_facet<time_get<CharT>>(is.getloc());
	// ...
    f.get(is, 0, is, err, &tm, command, fmt+1);
              ^

Using `nullptr` instead of `0` doesn't trigger the GCC 5.x warning:

> warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
2017-10-12 19:51:06 +02:00
Tomi Valkeinen
2032fccbb7 Fix valgrind warning about uninitialized variable use in to_stream()
tm variable is not initialized in to_stream(), and valgrind warns about
"Conditional jump or move depends on uninitialised value(s)".

This is a false positive, as strftime always reads tm_hour, even if it
ends up never using it. To silence the warnings, initialize tm to zero.
2017-10-03 15:22:49 -04:00