Skip to content

Commit c78840f

Browse files
authored
Merge pull request #15898 from xARSENICx/customize-library-date-format
feat(library): Add customizable date format option for Library and History
2 parents 869f19a + e9f35e9 commit c78840f

9 files changed

Lines changed: 338 additions & 64 deletions

File tree

src/library/basetracktablemodel.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ void BaseTrackTableModel::setApplyPlayedTrackColor(bool apply) {
115115
s_bApplyPlayedTrackColor = apply;
116116
}
117117

118+
const QString BaseTrackTableModel::kDateFormatDefault = QString();
119+
QString BaseTrackTableModel::s_dateFormat = BaseTrackTableModel::kDateFormatDefault;
120+
121+
void BaseTrackTableModel::setDateFormat(const QString& format) {
122+
s_dateFormat = format;
123+
}
124+
118125
BaseTrackTableModel::BaseTrackTableModel(
119126
QObject* parent,
120127
TrackCollectionManager* pTrackCollectionManager,
@@ -689,10 +696,10 @@ QVariant BaseTrackTableModel::roleValue(
689696
if (field == ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_DATETIMEADDED) {
690697
// Timestamp column in history feature:
691698
// Use localized date/time format without text: "5/20/98 03:40 AM"
692-
return mixxx::displayLocalDateTime(dt);
699+
return mixxx::displayLocalDateTime(dt, s_dateFormat);
693700
}
694701
// For Date Added, use just the date: "5/20/98"
695-
return dt.date();
702+
return mixxx::formatDate(dt.date(), s_dateFormat);
696703
}
697704
case ColumnCache::COLUMN_LIBRARYTABLE_LAST_PLAYED_AT: {
698705
QDateTime lastPlayedAt;
@@ -718,7 +725,7 @@ QVariant BaseTrackTableModel::roleValue(
718725
if (role == Qt::ToolTipRole || role == kDataExportRole) {
719726
return dt;
720727
}
721-
return dt.date();
728+
return mixxx::formatDate(dt.date(), s_dateFormat);
722729
}
723730
case ColumnCache::COLUMN_LIBRARYTABLE_BPM: {
724731
mixxx::Bpm bpm;

src/library/basetracktablemodel.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "library/trackmodel.h"
1010
#include "track/track_decl.h"
1111
#include "util/color/colorpalette.h"
12+
#include "util/datetime.h"
1213

1314
class TrackCollectionManager;
1415

@@ -132,6 +133,18 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
132133
static constexpr bool kApplyPlayedTrackColorDefault = true;
133134
static void setApplyPlayedTrackColor(bool apply);
134135

136+
enum class DateFormat {
137+
Native = 0, // System Default
138+
ISO8601 = 1, // yyyy-MM-dd
139+
RegionalShort = 2, // d/M/yy
140+
RegionalLong = 3, // dd.MM.yyyy
141+
Custom = 4,
142+
};
143+
Q_ENUM(DateFormat)
144+
145+
static const QString kDateFormatDefault;
146+
static void setDateFormat(const QString& format);
147+
135148
protected:
136149
// Build a map from the column names to their indices
137150
// used by fieldIndex().
@@ -309,4 +322,5 @@ class BaseTrackTableModel : public QAbstractTableModel, public TrackModel {
309322
static std::optional<ColorPalette> s_keyColorPalette;
310323

311324
static bool s_bApplyPlayedTrackColor;
325+
static QString s_dateFormat;
312326
};

src/library/library_prefs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,8 @@ const ConfigKey mixxx::library::prefs::kTagFetcherApplyCoverConfigKey =
114114
ConfigKey{
115115
mixxx::library::prefs::kConfigGroup,
116116
QStringLiteral("TagFetcherApplyCover")};
117+
118+
const ConfigKey mixxx::library::prefs::kDateFormatConfigKey =
119+
ConfigKey{
120+
mixxx::library::prefs::kConfigGroup,
121+
QStringLiteral("DateFormat")};

src/library/library_prefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ extern const ConfigKey kTagFetcherApplyTagsConfigKey;
5858

5959
extern const ConfigKey kTagFetcherApplyCoverConfigKey;
6060

61+
extern const ConfigKey kDateFormatConfigKey;
62+
6163
} // namespace prefs
6264

6365
} // namespace library

0 commit comments

Comments
 (0)