Comments (3)
I'm curious as to the context you are experiencing overflow. Can you show a brief code example? Thanks.
from date.
To be clearer, there are benefits to having year be 2 bytes:
- A
year_month_day
can be held in 4 bytes. Experience with boost::date_time over decades has shown that clients want a 4 byte date. - A 2 byte
year
can handle the civil calendar years -32767 to 32767 which is a larger range than nearly everyone needs. The civil calendar models the solar system to an accuracy of about 1 day in 4000 years. - The two-byte year is now standardized in C++20. And the limited range has enabled at least one implementation to make performance optimizations in the conversion to and from
sys_days
that would not be available had theyear
range been 4 bytes.
If all one needs is thousands or millions of years in the past or future, and not a date on the civil calendar, years
(plural) is not a bad choice. It has a 4 byte representation. And it would be trivial to create a duration (with a period of years
, kiloyears, or megayears) with other representations, including floating point.
If I knew more about your use case, I could almost certainly recommend a reasonable solution.
from date.
I've briefly scanned your code base linked above and see that you're already aware of the year::min()
and year::max()
functions being set to -32767 and 32767 respectively. My advice is to restrict your calendrical computations to that range. This range is what has been voted into the C++20 chrono specification: http://eel.is/c++draft/time.cal.year#members-19
If you have sufficient motivation to extend your range beyond these limits, here are the calendrical algorithms this library is based on and can be used with any number of bit-sized integers to achieve ranges far greater than +/- the age of the universe: http://howardhinnant.github.io/date_algorithms.html. The algorithms are in the public domain. Changing your copy of this library to use int
(as you've done) is a safe and correct method of extending these public domain algorithms to a range of +/-5.8 million years.
The motivations for staying within the more restricted range are outlined in my previous comment. Closing as not-to-be-fixed.
from date.
Related Issues (20)
- How to use date/tz.h properly HOT 4
- When I compile on x64 uwp I get the error HOT 1
- Waybar fails to compile with clang/libcxx because of date/tz.h HOT 8
- Undefined symbol HOT 1
- date_test_pass_parse_test fails with gcc (Debian 10.2.1-6) 10.2.1 20210110 HOT 1
- Date Parse: one pattern for ISO8601 DATE or DATE TIME HOT 6
- How can I convert between std::chrono::time_point and string (2023-12-06 00:46:45.801479+08)? HOT 4
- OSSFuzz Integration HOT 9
- Incorrect value of date::sys_info::save HOT 1
- Cannot override CMake options when fetching the library via FetchContent_Declare()
- .zip files have "text" git attribute HOT 1
- Possibly big performance improvement for `time_zone::to_sys()` HOT 10
- Failed to install tzdb HOT 4
- Transform date::local_seconds and timezone offset to struct tm HOT 1
- Missing tz.h header file when selecting compiler for ARM architecture HOT 1
- Opposite inner 'if' condition leads to a dead code block HOT 1
- Use timezone name like "-08:00" for `locate_zone()` HOT 2
- date::parse() doesn't have a formatting character for ISO 8601 strings without 'T' separator HOT 2
- How to parse datetime with milliseconds and timezone? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from date.