HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.08k stars 669 forks source link

Quick question about casting day, month and year #758

Open QuantDevHacks opened 1 year ago

QuantDevHacks commented 1 year ago

Quick question:

Might you tell me the reasoning behind day and month types being cast to unsigned, while year types are cast to int?

Thanks in advance.

HowardHinnant commented 1 year ago

The rationale was simply to enforce that negative integral values for month are never represented (ditto for day), while they are for year. It was realized that this design choice had a small cost in terms of homogeneity. And that was weighed against the small benefit of enforcing lack of negative values for month and day. I recognized this as a small-cost / small-benefit design decision and landed with where it is today.