Skip to content

Commit

Permalink
New utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Oct 16, 2023
1 parent 963286d commit 1ec0db5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/date.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ struct years {

struct date;

std::ostream& operator<<(std::ostream& stream, const year& month);
std::ostream& operator<<(std::ostream& stream, const month& month);
std::ostream& operator<<(std::ostream& stream, const day& month);
std::ostream& operator<<(std::ostream& stream, const date& date);

struct date {
Expand Down Expand Up @@ -510,6 +512,9 @@ struct date {
date local_day();

date date_from_string(std::string_view str);
year year_from_string(std::string_view str);
month month_from_string(std::string_view str);
day day_from_string(std::string_view str);

std::string date_to_string(const date& date);

Expand Down
20 changes: 20 additions & 0 deletions src/date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ budget::date budget::date_from_string(std::string_view str){
return {y, m, d};
}

budget::year budget::year_from_string(std::string_view str){
return budget::year{to_number<date_type>(str)};
}

budget::month budget::month_from_string(std::string_view str){
return budget::month{to_number<date_type>(str)};
}

budget::day budget::day_from_string(std::string_view str){
return budget::day{to_number<date_type>(str)};
}

std::string budget::date_to_string(const budget::date& date) {
std::string str(10, '0');

Expand Down Expand Up @@ -91,6 +103,14 @@ std::ostream& budget::operator<<(std::ostream& stream, const date& date){
return stream << date_to_string(date);
}

std::ostream& budget::operator<<(std::ostream& stream, const year& year){
return stream << year.value;
}

std::ostream& budget::operator<<(std::ostream& stream, const month& month){
return stream << month.as_short_string();
}

std::ostream& budget::operator<<(std::ostream& stream, const day& day){
return stream << day.value;
}

0 comments on commit 1ec0db5

Please sign in to comment.