[Bf-blender-cvs] [4befee9e620] filebrowser_redesign: UI: File Browser Use Friendly Relative Dates

Harley Acheson noreply at git.blender.org
Tue Aug 13 19:53:38 CEST 2019


Commit: 4befee9e620f3c0b17711b56cc19bdebd7d401f5
Author: Harley Acheson
Date:   Tue Aug 13 10:52:10 2019 -0700
Branches: filebrowser_redesign
https://developer.blender.org/rB4befee9e620f3c0b17711b56cc19bdebd7d401f5

UI: File Browser Use Friendly Relative Dates

Show 'Today' or 'Yesterday' in file list

===================================================================

M	release/datafiles/locale
M	release/scripts/addons
M	source/blender/blenlib/BLI_fileops.h
M	source/blender/blenlib/intern/BLI_filelist.c
M	source/blender/editors/space_file/file_draw.c

===================================================================

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 963e29bd16e..7327a198a42 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 963e29bd16e49c9bf227538c1042cf5c86cd9b28
+Subproject commit 7327a198a4221814d478dddb23088d54c96b4865
diff --git a/release/scripts/addons b/release/scripts/addons
index 2fa8a6214fc..d96b6d38d28 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 2fa8a6214fc8c07cbaa4f07d134bf1cb5957210f
+Subproject commit d96b6d38d28fa2ec3d2ba4d186d9e0a105e83d18
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h
index d8daa81b58d..6f1dd1ff5fc 100644
--- a/source/blender/blenlib/BLI_fileops.h
+++ b/source/blender/blenlib/BLI_fileops.h
@@ -100,7 +100,7 @@ void BLI_filelist_entry_mode_to_string(
     const struct stat *st, const bool compact, char r_mode1[], char r_mode2[], char r_mode3[]);
 void BLI_filelist_entry_owner_to_string(const struct stat *st, const bool compact, char r_owner[]);
 void BLI_filelist_entry_datetime_to_string(
-    const struct stat *st, const int64_t ts, const bool compact, char r_time[], char r_date[]);
+    const struct stat *st, const int64_t ts, const bool compact, char r_time[], char r_date[], const bool use_relative_str);
 
 /* Files */
 
diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c
index 33baba1e8a4..d10cef16b41 100644
--- a/source/blender/blenlib/intern/BLI_filelist.c
+++ b/source/blender/blenlib/intern/BLI_filelist.c
@@ -352,9 +352,28 @@ void BLI_filelist_entry_datetime_to_string(const struct stat *st,
                                            const int64_t ts,
                                            const bool compact,
                                            char r_time[FILELIST_DIRENTRY_TIME_LEN],
-                                           char r_date[FILELIST_DIRENTRY_DATE_LEN])
+                                           char r_date[FILELIST_DIRENTRY_DATE_LEN],
+                                           const bool use_relative_str
+  )
 {
-  time_t ts_mtime = ts;
+  int today_year = 0;
+  int today_yday = 0;
+  int yesterday_year = 0;
+  int yesterday_yday = 0;
+  if (use_relative_str) {
+    /* Localtime() has only one buffer so need to get data out before called again. */
+    const time_t ts_now = time(NULL);
+    struct tm *today = localtime(&ts_now);
+    today_year = today->tm_year;
+    today_yday = today->tm_yday;
+    /* Handle a yesterday that spans a year */
+    today->tm_mday--;
+    mktime(today);
+    yesterday_year = today->tm_year;
+    yesterday_yday = today->tm_yday;
+  }
+
+  const time_t ts_mtime = ts;
   const struct tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
   const time_t zero = 0;
 
@@ -367,10 +386,19 @@ void BLI_filelist_entry_datetime_to_string(const struct stat *st,
     strftime(r_time, sizeof(*r_time) * FILELIST_DIRENTRY_TIME_LEN, "%H:%M", tm);
   }
   if (r_date) {
-    strftime(r_date,
-             sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN,
-             compact ? "%d/%m/%y" : "%d %b %Y",
-             tm);
+    if (use_relative_str && (tm->tm_year == today_year) && (tm->tm_yday == today_yday)) {
+      BLI_strncpy(r_date, "Today", sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN);
+    }
+    else if (use_relative_str && (tm->tm_year == yesterday_year) &&
+             (tm->tm_yday == yesterday_yday)) {
+      BLI_strncpy(r_date, "Yesterday", sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN);
+    }
+    else {
+      strftime(r_date,
+               sizeof(*r_date) * FILELIST_DIRENTRY_DATE_LEN,
+               compact ? "%d/%m/%y" : "%d %b %Y",
+               tm);
+    }
   }
 }
 
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index ea66069a01e..30dc62aff63 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -543,9 +543,9 @@ static const char *filelist_get_details_column_string(FileListColumns column,
       if (!(file->typeflag & FILE_TYPE_BLENDERLIB) && !FILENAME_IS_CURRPAR(file->relpath)) {
         if ((file->entry->datetime_str[0] == '\0') || update_stat_strings) {
           char date[16], time[8];
-          BLI_filelist_entry_datetime_to_string(NULL, file->entry->time, small_size, time, date);
+          BLI_filelist_entry_datetime_to_string(NULL, file->entry->time, small_size, time, date, true);
           BLI_snprintf(
-              file->entry->datetime_str, sizeof(file->entry->datetime_str), "%s, %s", date, time);
+              file->entry->datetime_str, sizeof(file->entry->datetime_str), "%s %s", date, time);
         }
 
         return file->entry->datetime_str;



More information about the Bf-blender-cvs mailing list