mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:40:06 +00:00 
			
		
		
		
	QDate::toStdSysDays is needlessly behind __cpp_lib_chrono >= 201907L
This commit is contained in:
		
							parent
							
								
									1479525c4a
								
							
						
					
					
						commit
						5a078800e4
					
				
					 4 changed files with 56 additions and 4 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| #include "animation_dock_widget.hpp" | ||||
| #include "ui_animation_dock_widget.h" | ||||
| 
 | ||||
| #include <scwx/qt/util/time.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <QTimer> | ||||
|  | @ -65,7 +66,7 @@ AnimationDockWidget::AnimationDockWidget(QWidget* parent) : | |||
|    ui->dateEdit->setDate(currentDate); | ||||
|    ui->timeEdit->setTime(currentTime); | ||||
|    ui->dateEdit->setMaximumDate(currentDateTime.date()); | ||||
|    p->selectedDate_ = currentDate.toStdSysDays(); | ||||
|    p->selectedDate_ = util::SysDays(currentDate); | ||||
|    p->selectedTime_ = | ||||
|       std::chrono::seconds(currentTime.msecsSinceStartOfDay() / 1000); | ||||
| 
 | ||||
|  | @ -129,7 +130,7 @@ void AnimationDockWidgetImpl::ConnectSignals() | |||
|       { | ||||
|          if (date.isValid()) | ||||
|          { | ||||
|             selectedDate_ = date.toStdSysDays(); | ||||
|             selectedDate_ = util::SysDays(date); | ||||
|             emit self_->DateTimeChanged(selectedDate_ + selectedTime_); | ||||
|          } | ||||
|       }); | ||||
|  |  | |||
							
								
								
									
										24
									
								
								scwx-qt/source/scwx/qt/util/time.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								scwx-qt/source/scwx/qt/util/time.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| #include <scwx/qt/util/time.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| 
 | ||||
| std::chrono::sys_days SysDays(const QDate& date) | ||||
| { | ||||
|    using namespace std::chrono; | ||||
|    using sys_days             = time_point<system_clock, days>; | ||||
|    constexpr auto julianEpoch = sys_days {-4713y / November / 24d}; | ||||
|    constexpr auto unixEpoch   = sys_days {1970y / January / 1d}; | ||||
|    constexpr auto offset      = std::chrono::days(julianEpoch - unixEpoch); | ||||
| 
 | ||||
|    return std::chrono::sys_days(std::chrono::days(date.toJulianDay()) + | ||||
|                                 julianEpoch); | ||||
| } | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										25
									
								
								scwx-qt/source/scwx/qt/util/time.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								scwx-qt/source/scwx/qt/util/time.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <chrono> | ||||
| 
 | ||||
| #include <QDateTime> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief Convert QDate to std::chrono::sys_days. | ||||
|  * | ||||
|  * @param [in] date Date to convert | ||||
|  * | ||||
|  * @return Days | ||||
|  */ | ||||
| std::chrono::sys_days SysDays(const QDate& date); | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat