Use QDateTime::currentSecsSinceEpoch

This commit is contained in:
Jonas Kvinge 2024-04-23 16:48:51 +02:00
parent 579349b104
commit 398db964b8
6 changed files with 11 additions and 11 deletions

View File

@ -248,7 +248,7 @@ bool TagReaderTagLib::ReadFile(const QString &filename, spb::tagreader::SongMeta
song->set_ctime(song->mtime());
}
song->set_lastseen(QDateTime::currentDateTime().toSecsSinceEpoch());
song->set_lastseen(QDateTime::currentSecsSinceEpoch());
std::unique_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(filename));
if (fileref->isNull()) {

View File

@ -1914,7 +1914,7 @@ void CollectionBackend::IncrementPlayCount(const int id) {
SqlQuery q(db);
q.prepare(QStringLiteral("UPDATE %1 SET playcount = playcount + 1, lastplayed = :now WHERE ROWID = :id").arg(songs_table_));
q.BindValue(QStringLiteral(":now"), QDateTime::currentDateTime().toSecsSinceEpoch());
q.BindValue(QStringLiteral(":now"), QDateTime::currentSecsSinceEpoch());
q.BindValue(QStringLiteral(":id"), id);
if (!q.Exec()) {
db_->ReportErrors(q);
@ -2201,7 +2201,7 @@ void CollectionBackend::UpdateLastSeen(const int directory_id, const int expire_
SqlQuery q(db);
q.prepare(QStringLiteral("UPDATE %1 SET lastseen = :lastseen WHERE directory_id = :directory_id AND unavailable = 0").arg(songs_table_));
q.BindValue(QStringLiteral(":lastseen"), QDateTime::currentDateTime().toSecsSinceEpoch());
q.BindValue(QStringLiteral(":lastseen"), QDateTime::currentSecsSinceEpoch());
q.BindValue(QStringLiteral(":directory_id"), directory_id);
if (!q.Exec()) {
db_->ReportErrors(q);
@ -2222,7 +2222,7 @@ void CollectionBackend::ExpireSongs(const int directory_id, const int expire_una
SqlQuery q(db);
q.prepare(QStringLiteral("SELECT %1 FROM %2 LEFT JOIN playlist_items ON %2.ROWID = playlist_items.collection_id WHERE %2.directory_id = :directory_id AND %2.unavailable = 1 AND %2.lastseen > 0 AND %2.lastseen < :time AND playlist_items.collection_id IS NULL").arg(Song::JoinSpec(songs_table_), songs_table_));
q.BindValue(QStringLiteral(":directory_id"), directory_id);
q.BindValue(QStringLiteral(":time"), QDateTime::currentDateTime().toSecsSinceEpoch() - (expire_unavailable_songs_days * 86400));
q.BindValue(QStringLiteral(":time"), QDateTime::currentSecsSinceEpoch() - (expire_unavailable_songs_days * 86400));
if (!q.Exec()) {
db_->ReportErrors(q);
return;

View File

@ -29,7 +29,7 @@ CollectionFilterOptions::CollectionFilterOptions() : filter_mode_(FilterMode::Al
bool CollectionFilterOptions::Matches(const Song &song) const {
if (max_age_ != -1) {
const qint64 cutoff = QDateTime::currentDateTime().toSecsSinceEpoch() - max_age_;
const qint64 cutoff = QDateTime::currentSecsSinceEpoch() - max_age_;
if (song.ctime() <= cutoff) return false;
}

View File

@ -417,7 +417,7 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle
transaction.SetKnownSubdirs(subdirs);
transaction.AddToProgressMax(files_count);
ScanSubdirectory(dir.path, CollectionSubdirectory(), files_count, &transaction);
last_scan_time_ = QDateTime::currentDateTime().toSecsSinceEpoch();
last_scan_time_ = QDateTime::currentSecsSinceEpoch();
}
else {
// We can do an incremental scan - looking at the mtimes of each subdirectory and only rescan if the directory has changed.
@ -434,7 +434,7 @@ void CollectionWatcher::AddDirectory(const CollectionDirectory &dir, const Colle
if (monitor_) AddWatch(dir, subdir.path);
}
last_scan_time_ = QDateTime::currentDateTime().toSecsSinceEpoch();
last_scan_time_ = QDateTime::currentSecsSinceEpoch();
}
@ -1198,7 +1198,7 @@ void CollectionWatcher::FullScanAsync() {
void CollectionWatcher::IncrementalScanCheck() {
qint64 duration = QDateTime::currentDateTime().toSecsSinceEpoch() - last_scan_time_;
qint64 duration = QDateTime::currentSecsSinceEpoch() - last_scan_time_;
if (duration >= 86400) {
qLog(Debug) << "Performing periodic incremental scan.";
IncrementalScanNow();
@ -1240,7 +1240,7 @@ void CollectionWatcher::PerformScan(const bool incremental, const bool ignore_mt
}
last_scan_time_ = QDateTime::currentDateTime().toSecsSinceEpoch();
last_scan_time_ = QDateTime::currentSecsSinceEpoch();
emit CompilationsNeedUpdating();

View File

@ -532,7 +532,7 @@ void Player::UnPause() {
if (current_item_ && pause_time_.isValid()) {
const Song &song = current_item_->Metadata();
if (url_handlers_.contains(song.url().scheme()) && song.stream_url_can_expire()) {
const quint64 time = QDateTime::currentDateTime().toSecsSinceEpoch() - pause_time_.toSecsSinceEpoch();
const quint64 time = QDateTime::currentSecsSinceEpoch() - pause_time_.toSecsSinceEpoch();
if (time >= 30) { // Stream URL might be expired.
qLog(Debug) << "Re-requesting stream URL for" << song.url();
play_offset_nanosec_ = engine_->position_nanosec();

View File

@ -68,7 +68,7 @@ TEST(UtilitiesTest, WordyTimeNanosec) {}
TEST(UtilitiesTest, Ago) {
ASSERT_EQ(Utilities::Ago(QDateTime::currentDateTime().toSecsSinceEpoch() - 604800, QLocale()), QStringLiteral("7 days ago"));
ASSERT_EQ(Utilities::Ago(QDateTime::currentSecsSinceEpoch() - 604800, QLocale()), QStringLiteral("7 days ago"));
}