Use friendly date format

This commit is contained in:
cutefishd 2021-04-22 10:24:10 +08:00
parent c7d09c918f
commit 8879e12625
7 changed files with 58 additions and 2 deletions

View file

@ -34,6 +34,7 @@ add_executable(cutefish-filemanager
desktop/desktopview.cpp
desktop/desktopsettings.cpp
helper/datehelper.cpp
helper/thumbnailer.cpp
helper/pathhistory.cpp

34
helper/datehelper.cpp Normal file
View file

@ -0,0 +1,34 @@
#include "datehelper.h"
#include <QDateTime>
DateHelper::DateHelper(QObject *parent) : QObject(parent)
{
}
QString DateHelper::friendlyTime(const QDateTime &time)
{
QDateTime now = QDateTime::currentDateTime();
qint64 minutes = qRound64(time.secsTo(now) / 60.0f);
if (minutes < 1)
return tr("Now");
else if (minutes == 1)
return tr("1 minute ago");
else if (minutes < 60)
return tr("%1 minutes ago").arg(minutes);
qint64 hours = qRound64(minutes / 60.0f);
if (hours == 1)
return tr("1 hour ago");
else if (hours < 24)
return tr("%1 hours ago").arg(hours);
qint64 days = qRound64(hours / 24.0f);
if (days == 1)
return tr("1 day ago");
else if (days <= 10)
return tr("%1 days ago").arg(days);
return time.toString(Qt::DefaultLocaleShortDate);
}

16
helper/datehelper.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef DATEHELPER_H
#define DATEHELPER_H
#include <QObject>
class DateHelper : public QObject
{
Q_OBJECT
public:
explicit DateHelper(QObject *parent = nullptr);
Q_INVOKABLE static QString friendlyTime(const QDateTime &time);
};
#endif // DATEHELPER_H

View file

@ -34,6 +34,7 @@
#include "desktop/desktopsettings.h"
#include "desktop/desktopview.h"
#include "helper/thumbnailer.h"
#include "helper/datehelper.h"
int main(int argc, char *argv[])
{

View file

@ -28,6 +28,8 @@
#include "../dialogs/propertiesdialog.h"
#include "../dialogs/createfolderdialog.h"
#include "../helper/datehelper.h"
// Qt
#include <QDir>
#include <QMenu>
@ -184,7 +186,7 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
return QVariant();
}
case ModifiedRole: {
return item.timeString(KFileItem::ModificationTime);
return DateHelper::friendlyTime(item.time(KFileItem::ModificationTime));
}
default:
break;

View file

@ -585,9 +585,9 @@ GridView {
visible: false
wrapMode: TextEdit.Wrap
horizontalAlignment: TextEdit.AlignHCenter
z: 999
topPadding: FishUI.Units.smallSpacing
bottomPadding: FishUI.Units.smallSpacing
z: 999
property Item targetItem: null
@ -597,6 +597,7 @@ GridView {
width = targetItem.width - FishUI.Units.smallSpacing
height = targetItem.labelArea.paintedHeight + FishUI.Units.largeSpacing * 2
x = targetItem.x + Math.abs(Math.min(control.contentX, control.originX))
x = targetItem.x + (targetItem.width - _editor.width)
y = pos.y - FishUI.Units.largeSpacing
text = targetItem.labelArea.text
targetItem.labelArea.visible = false

View file

@ -3,6 +3,7 @@ import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
import FishUI 1.0 as FishUI
import Cutefish.FileManager 1.0
Item {
id: _listItem