Simpify calendar generation, single loop handles both first week and subsequent weeks.
This commit is contained in:
		
							parent
							
								
									f6b2005687
								
							
						
					
					
						commit
						218bb3bc2b
					
				|  | @ -61,21 +61,13 @@ std::string calendar_text(const waybar_time& wtime, const date::weekday& first_d | ||||||
|   if (empty_days > 0) { |   if (empty_days > 0) { | ||||||
|     os << std::string(empty_days * 3 - 1, ' '); |     os << std::string(empty_days * 3 - 1, ' '); | ||||||
|   } |   } | ||||||
|   auto d = date::day(1); |  | ||||||
|   do { |  | ||||||
|     if (wd != first_dow) os << ' '; |  | ||||||
|     if (d == curr_day) { |  | ||||||
|       os << "<b><u>" << date::format("%e", d) << "</u></b>"; |  | ||||||
|     } else { |  | ||||||
|       os << date::format("%e", d); |  | ||||||
|     } |  | ||||||
|     ++d; |  | ||||||
|   } while (++wd != first_dow); |  | ||||||
| 
 |  | ||||||
|   // Following weeks.
 |  | ||||||
|   auto last_day = (ym/date::literals::last).day(); |   auto last_day = (ym/date::literals::last).day(); | ||||||
|   for ( ; d <= last_day; ++d, ++wd) { |   for (auto d = date::day(1); d <= last_day; ++d, ++wd) { | ||||||
|     os << ((wd == first_dow) ? '\n' : ' '); |     if (wd != first_dow) { | ||||||
|  |       os << ' '; | ||||||
|  |     } else if (unsigned(d) != 1) { | ||||||
|  |       os << '\n'; | ||||||
|  |     } | ||||||
|     if (d == curr_day) { |     if (d == curr_day) { | ||||||
|       os << "<b><u>" << date::format("%e", d) << "</u></b>"; |       os << "<b><u>" << date::format("%e", d) << "</u></b>"; | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue