Skip to content

Commit

Permalink
Get current date properly (#2185)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryo Nakano <ryonakaknock3@gmail.com>
  • Loading branch information
Jeremy Wootten and ryonakano authored May 6, 2023
1 parent 5b54eb0 commit 70ab107
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libcore/Enums.vala
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ namespace Files {
}

public enum RenameDateSource {
DEFAULT,
CREATED,
MODIFIED,
NOW,
INVALID;

public string to_string () {
switch (this) {
case RenameDateSource.DEFAULT:
case RenameDateSource.CREATED:
return _("Date created");
case RenameDateSource.MODIFIED:
return _("Date Modified");
Expand Down
28 changes: 18 additions & 10 deletions src/Dialogs/BulkRenamer/RenamerModifier.vala
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public class Files.RenamerModifier : Object {
var date_source_combo = new Gtk.ComboBoxText () {
valign = Gtk.Align.CENTER
};
date_source_combo.insert (RenameDateSource.DEFAULT, "DEFAULT",
RenameDateSource.DEFAULT.to_string ());
date_source_combo.insert (RenameDateSource.CREATED, "DEFAULT",
RenameDateSource.CREATED.to_string ());
date_source_combo.insert (RenameDateSource.MODIFIED, "MODIFICATION_DATE",
RenameDateSource.MODIFIED.to_string ());
date_source_combo.insert (RenameDateSource.NOW, "CURRENT_DATE",
Expand Down Expand Up @@ -241,20 +241,20 @@ public class Files.RenamerModifier : Object {
break;

case RenameMode.DATETIME:
uint64 dt;
switch (source) {
case RenameDateSource.MODIFIED:
dt = file.modified;
new_text = get_formated_datetime ((int64)file.modified);
break;
case RenameDateSource.CREATED:
new_text = get_formated_datetime ((int64)file.created);
break;
case RenameDateSource.NOW:
dt = (uint64)get_monotonic_time ();
new_text = get_formated_datetime (-1);
break;
default: // Created
dt = file.info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED);
default:
break;
}

new_text = get_formated_datetime (dt);
break;

default:
Expand All @@ -275,8 +275,16 @@ public class Files.RenamerModifier : Object {
return input;
}

public string get_formated_datetime (uint64 dt) {
var datetime = new DateTime.from_unix_local ((int64)dt);
public string get_formated_datetime (int64 dt) {
DateTime datetime;
if (dt > 0) {
datetime = new DateTime.from_unix_local (dt);
} else if (dt < 0) {
datetime = new DateTime.now ();
} else {
return "";
}

switch ((uint)format) {
case RenameDateFormat.DEFAULT_DATETIME:
return datetime.format (Granite.DateTime.get_default_date_format (false, true, true).
Expand Down

0 comments on commit 70ab107

Please sign in to comment.