Skip to main content
added 125 characters in body
Source Link
G. Sliepen
  • 69.5k
  • 3
  • 75
  • 180

Make better use of the standard library

C++20 comes with extensive facilities to deal with dates. Instead of storing year, month and day as integers, use std::chrono::year_month_day. Also, it has facilities to format to string and parse from string using arbitrary date formats. This type also avoid most of the issues J_H mentioned.

In fact, I would not create a class DateData at all, and rather just create functions that do whatever conversions you need that don't have a simple counterpart in the standard library, like parsing a string from any"any of the "legal"legal" formats.

Also, the less you use old C types and the more you use std::chrono types, the simpler your code will be.

It's very US-centric

Your code only deals with ISO and US date formats. However, most other countries in the world use a different (some would say a more sensible) order for day, month and year. So this makes your code less usable outside the US. It would be nice if you can avoid hardcoding the date formats and the locale used.

Also, even if you just deal with the US, what about timezones?

Make better use of the standard library

C++20 comes with extensive facilities to deal with dates. Instead of storing year, month and day as integers, use std::chrono::year_month_day. Also, it has facilities to format to string and parse from string using arbitrary date formats. This type also avoid most of the issues J_H mentioned.

In fact, I would not create a class DateData at all, and rather just create functions that do whatever conversions you need that don't have a simple counterpart in the standard library, like parsing a string from any of the "legal" formats.

Also, the less you use old C types and the more you use std::chrono types, the simpler your code will be.

It's very US-centric

Your code only deals with ISO and US date formats. However, most other countries in the world use a different (some would say a more sensible) order for day, month and year. So this makes your code less usable outside the US. It would be nice if you can avoid hardcoding the date formats and the locale used.

Make better use of the standard library

C++20 comes with extensive facilities to deal with dates. Instead of storing year, month and day as integers, use std::chrono::year_month_day. Also, it has facilities to format to string and parse from string using arbitrary date formats. This type also avoid most of the issues J_H mentioned.

In fact, I would not create a class DateData at all, and rather just create functions that do whatever conversions you need that don't have a simple counterpart in the standard library, like parsing a string from "any of the legal" formats.

Also, the less you use old C types and the more you use std::chrono types, the simpler your code will be.

It's very US-centric

Your code only deals with ISO and US date formats. However, most other countries in the world use a different (some would say a more sensible) order for day, month and year. So this makes your code less usable outside the US. It would be nice if you can avoid hardcoding the date formats and the locale used.

Also, even if you just deal with the US, what about timezones?

Source Link
G. Sliepen
  • 69.5k
  • 3
  • 75
  • 180

Make better use of the standard library

C++20 comes with extensive facilities to deal with dates. Instead of storing year, month and day as integers, use std::chrono::year_month_day. Also, it has facilities to format to string and parse from string using arbitrary date formats. This type also avoid most of the issues J_H mentioned.

In fact, I would not create a class DateData at all, and rather just create functions that do whatever conversions you need that don't have a simple counterpart in the standard library, like parsing a string from any of the "legal" formats.

Also, the less you use old C types and the more you use std::chrono types, the simpler your code will be.

It's very US-centric

Your code only deals with ISO and US date formats. However, most other countries in the world use a different (some would say a more sensible) order for day, month and year. So this makes your code less usable outside the US. It would be nice if you can avoid hardcoding the date formats and the locale used.