mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:50:06 +00:00 
			
		
		
		
	Use constexpr instead of #define where possible in time.cpp
This commit is contained in:
		
							parent
							
								
									b60318c393
								
							
						
					
					
						commit
						163b703964
					
				
					 1 changed files with 12 additions and 8 deletions
				
			
		|  | @ -60,15 +60,19 @@ std::string TimeString(std::chrono::system_clock::time_point time, | ||||||
|    using namespace std::chrono; |    using namespace std::chrono; | ||||||
| 
 | 
 | ||||||
| #if (__cpp_lib_chrono >= 201907L) | #if (__cpp_lib_chrono >= 201907L) | ||||||
| #   define FORMAT_STRING_24_HOUR "{:%Y-%m-%d %H:%M:%S %Z}" |  | ||||||
| #   define FORMAT_STRING_12_HOUR "{:%Y-%m-%d %I:%M:%S %p %Z}" |  | ||||||
|    namespace date = std::chrono; |    namespace date = std::chrono; | ||||||
|    namespace df   = std; |    namespace df   = std; | ||||||
|  | 
 | ||||||
|  |    static constexpr std::string_view kFormatString24Hour = | ||||||
|  |       "{:%Y-%m-%d %H:%M:%S %Z}"; | ||||||
|  |    static constexpr std::string_view kFormatString12Hour = | ||||||
|  |       "{:%Y-%m-%d %I:%M:%S %p %Z}"; | ||||||
| #else | #else | ||||||
| #   define FORMAT_STRING_24_HOUR "%Y-%m-%d %H:%M:%S %Z" |  | ||||||
| #   define FORMAT_STRING_12_HOUR "%Y-%m-%d %I:%M:%S %p %Z" |  | ||||||
|    using namespace date; |    using namespace date; | ||||||
|    namespace df = date; |    namespace df = date; | ||||||
|  | 
 | ||||||
|  | #   define kFormatString24Hour "%Y-%m-%d %H:%M:%S %Z" | ||||||
|  | #   define kFormatString12Hour "%Y-%m-%d %I:%M:%S %p %Z" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|    auto               timeInSeconds = time_point_cast<seconds>(time); |    auto               timeInSeconds = time_point_cast<seconds>(time); | ||||||
|  | @ -84,11 +88,11 @@ std::string TimeString(std::chrono::system_clock::time_point time, | ||||||
| 
 | 
 | ||||||
|             if (clockFormat == ClockFormat::_24Hour) |             if (clockFormat == ClockFormat::_24Hour) | ||||||
|             { |             { | ||||||
|                os << df::format(FORMAT_STRING_24_HOUR, zt); |                os << df::format(kFormatString24Hour, zt); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                os << df::format(FORMAT_STRING_12_HOUR, zt); |                os << df::format(kFormatString12Hour, zt); | ||||||
|             } |             } | ||||||
|          } |          } | ||||||
|          catch (const std::exception& ex) |          catch (const std::exception& ex) | ||||||
|  | @ -110,11 +114,11 @@ std::string TimeString(std::chrono::system_clock::time_point time, | ||||||
|       { |       { | ||||||
|          if (clockFormat == ClockFormat::_24Hour) |          if (clockFormat == ClockFormat::_24Hour) | ||||||
|          { |          { | ||||||
|             os << df::format(FORMAT_STRING_24_HOUR, timeInSeconds); |             os << df::format(kFormatString24Hour, timeInSeconds); | ||||||
|          } |          } | ||||||
|          else |          else | ||||||
|          { |          { | ||||||
|             os << df::format(FORMAT_STRING_12_HOUR, timeInSeconds); |             os << df::format(kFormatString12Hour, timeInSeconds); | ||||||
|          } |          } | ||||||
|       } |       } | ||||||
|    } |    } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat