mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:40:05 +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; | ||||
| 
 | ||||
| #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 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 | ||||
| #   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; | ||||
|    namespace df = date; | ||||
| 
 | ||||
| #   define kFormatString24Hour "%Y-%m-%d %H:%M:%S %Z" | ||||
| #   define kFormatString12Hour "%Y-%m-%d %I:%M:%S %p %Z" | ||||
| #endif | ||||
| 
 | ||||
|    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) | ||||
|             { | ||||
|                os << df::format(FORMAT_STRING_24_HOUR, zt); | ||||
|                os << df::format(kFormatString24Hour, zt); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                os << df::format(FORMAT_STRING_12_HOUR, zt); | ||||
|                os << df::format(kFormatString12Hour, zt); | ||||
|             } | ||||
|          } | ||||
|          catch (const std::exception& ex) | ||||
|  | @ -110,11 +114,11 @@ std::string TimeString(std::chrono::system_clock::time_point time, | |||
|       { | ||||
|          if (clockFormat == ClockFormat::_24Hour) | ||||
|          { | ||||
|             os << df::format(FORMAT_STRING_24_HOUR, timeInSeconds); | ||||
|             os << df::format(kFormatString24Hour, timeInSeconds); | ||||
|          } | ||||
|          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