@@ -20,7 +20,7 @@ using namespace budget;
2020
2121void budget::overview_page (html_writer& w, const httplib::Request& req) {
2222 if (req.matches .size () == 3 ) {
23- display_month_overview (to_number< size_t > (req.matches [2 ]), to_number< size_t > (req.matches [1 ]), w);
23+ display_month_overview (month_from_string (req.matches [2 ]), year_from_string (req.matches [1 ]), w);
2424 } else {
2525 auto today = budget::local_day ();
2626 display_month_overview (today.month (), today.year (), w);
@@ -43,7 +43,7 @@ void budget::overview_aggregate_year_page(html_writer& w, const httplib::Request
4343 std::string const separator = config_value (" aggregate_separator" , " /" );
4444
4545 if (req.matches .size () == 2 ) {
46- aggregate_year_overview (w, full, disable_groups, separator, to_number< size_t > (req.matches [1 ]));
46+ aggregate_year_overview (w, full, disable_groups, separator, year_from_string (req.matches [1 ]));
4747 } else {
4848 auto today = budget::local_day ();
4949 aggregate_year_overview (w, full, disable_groups, separator, today.year ());
@@ -57,7 +57,7 @@ void budget::overview_aggregate_year_fv_page(html_writer& w, const httplib::Requ
5757 std::string const separator = config_value (" aggregate_separator" , " /" );
5858
5959 if (req.matches .size () == 2 ) {
60- aggregate_year_fv_overview (w, full, disable_groups, separator, to_number< size_t > (req.matches [1 ]));
60+ aggregate_year_fv_overview (w, full, disable_groups, separator, year_from_string (req.matches [1 ]));
6161 } else {
6262 auto today = budget::local_day ();
6363 aggregate_year_fv_overview (w, full, disable_groups, separator, today.year ());
@@ -71,7 +71,7 @@ void budget::overview_aggregate_year_month_page(html_writer& w, const httplib::R
7171 std::string const separator = config_value (" aggregate_separator" , " /" );
7272
7373 if (req.matches .size () == 2 ) {
74- aggregate_year_month_overview (w, full, disable_groups, separator, to_number< size_t > (req.matches [1 ]));
74+ aggregate_year_month_overview (w, full, disable_groups, separator, year_from_string (req.matches [1 ]));
7575 } else {
7676 auto today = budget::local_day ();
7777 aggregate_year_month_overview (w, full, disable_groups, separator, today.year ());
@@ -85,7 +85,7 @@ void budget::overview_aggregate_month_page(html_writer& w, const httplib::Reques
8585 std::string const separator = config_value (" aggregate_separator" , " /" );
8686
8787 if (req.matches .size () == 3 ) {
88- aggregate_month_overview (w, full, disable_groups, separator, to_number< size_t > (req.matches [2 ]), to_number< size_t > (req.matches [1 ]));
88+ aggregate_month_overview (w, full, disable_groups, separator, month_from_string (req.matches [2 ]), year_from_string (req.matches [1 ]));
8989 } else {
9090 auto today = budget::local_day ();
9191 aggregate_month_overview (w, full, disable_groups, separator, today.month (), today.year ());
@@ -95,7 +95,7 @@ void budget::overview_aggregate_month_page(html_writer& w, const httplib::Reques
9595void budget::overview_year_page (html_writer& w, const httplib::Request& req) {
9696 budget::year year = budget::local_day ().year ();
9797 if (req.matches .size () == 2 ) {
98- year = to_number< size_t > (req.matches [1 ]);
98+ year = year_from_string (req.matches [1 ]);
9999 }
100100
101101 // Display the Summary Yearly Overview
@@ -126,14 +126,14 @@ void budget::overview_year_page(html_writer& w, const httplib::Request& req) {
126126
127127 ss << " ]}," ;
128128
129- if (year - 1 >= start_year (w.cache )) {
130- ss << " { name: '" << year - 1 << " Expenses'," ;
129+ if (year - date_type ( 1 ) >= start_year (w.cache )) {
130+ ss << " { name: '" << year - date_type ( 1 ) << " Expenses'," ;
131131 ss << " data: [" ;
132132
133- for (budget::month month = start_month (w.cache , year - 1 ) ; month < 13 ; ++month) {
134- auto sum = fold_left_auto (all_expenses_month (w.cache , year - 1 , month) | to_amount);
133+ for (budget::month month = start_month (w.cache , year - date_type ( 1 )) ; month. is_valid () ; ++month) {
134+ auto sum = fold_left_auto (all_expenses_month (w.cache , year - date_type ( 1 ) , month) | to_amount);
135135
136- const std::string date = std::format (" Date.UTC({},{},1)" , year.value , month.value - 1 );
136+ const std::string date = std::format (" Date.UTC({},{},1)" , year.value , month.value - date_type ( 1 ) );
137137 ss << " [" << date << " ," << budget::money_to_string (sum) << " ]," ;
138138 }
139139
@@ -168,15 +168,15 @@ void budget::overview_year_page(html_writer& w, const httplib::Request& req) {
168168
169169 ss << " ]}," ;
170170
171- if (year - 1 >= start_year (w.cache )) {
172- ss << " { name: '" << year - 1 << " Expenses'," ;
171+ if (year - date_type ( 1 ) >= start_year (w.cache )) {
172+ ss << " { name: '" << year - date_type ( 1 ) << " Expenses'," ;
173173 ss << " data: [" ;
174174
175- for (budget::month month = start_month (w.cache , year - 1 ) ; month < 13 ; ++month) {
175+ for (budget::month month = start_month (w.cache , year - date_type ( 1 )) ; month. is_valid () ; ++month) {
176176 auto sum =
177- get_base_income (w.cache , budget::date (year - 1 , month, 2 )) + fold_left_auto (all_earnings_month (w.cache , year - 1 , month) | to_amount);
177+ get_base_income (w.cache , budget::date (year - date_type ( 1 ) , month, 2 )) + fold_left_auto (all_earnings_month (w.cache , year - date_type ( 1 ) , month) | to_amount);
178178
179- const std::string date = std::format (" Date.UTC({},{},1)" , year.value , month.value - 1 );
179+ const std::string date = std::format (" Date.UTC({},{},1)" , year.value , month.value - date_type ( 1 ) );
180180 ss << " [" << date << " ," << budget::money_to_string (sum) << " ]," ;
181181 }
182182
@@ -209,15 +209,11 @@ void budget::time_graph_savings_rate_page(html_writer& w) {
209209
210210 auto sy = start_year (w.cache );
211211
212- for (unsigned short j = sy; j <= budget::local_day ().year (); ++j) {
213- budget::year const year = j;
214-
212+ for (budget::year year = sy; year <= budget::local_day ().year (); ++year) {
215213 const auto sm = start_month (w.cache , year);
216214 const auto last = last_month (year);
217215
218- for (unsigned short i = sm; i < last; ++i) {
219- budget::month const month = i;
220-
216+ for (budget::month month = sm; month < last; ++month) {
221217 auto status = budget::compute_month_status (w.cache , year, month);
222218
223219 auto savings = status.income - status.expenses ;
@@ -286,15 +282,11 @@ void budget::time_graph_tax_rate_page(html_writer& w) {
286282
287283 double max = 1.0 ;
288284
289- for (unsigned short j = sy; j <= budget::local_day ().year (); ++j) {
290- budget::year const year = j;
291-
285+ for (budget::year year = sy; year <= budget::local_day ().year (); ++year) {
292286 const auto sm = start_month (w.cache , year);
293287 const auto last = last_month (year);
294288
295- for (unsigned short i = sm; i < last; ++i) {
296- budget::month const month = i;
297-
289+ for (budget::month month = sm; month < last; ++month) {
298290 auto status = budget::compute_month_status (w.cache , year, month);
299291
300292 double tax_rate = status.taxes / status.income ;
@@ -428,7 +420,7 @@ void budget::side_overview_page(html_writer& w, const httplib::Request& req) {
428420 }
429421
430422 if (req.matches .size () == 3 ) {
431- display_side_month_overview (to_number< size_t > (req.matches [2 ]), to_number< size_t > (req.matches [1 ]), w);
423+ display_side_month_overview (month_from_string (req.matches [2 ]), year_from_string (req.matches [1 ]), w);
432424 } else {
433425 auto today = budget::local_day ();
434426 display_side_month_overview (today.month (), today.year (), w);
0 commit comments