Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorHarley Acheson <harley.acheson@gmail.com>2019-08-13 20:52:10 +0300
committerHarley Acheson <harley.acheson@gmail.com>2019-08-13 20:52:10 +0300
commit4befee9e620f3c0b17711b56cc19bdebd7d401f5 (patch)
treecd939a565b8a13cd70ac4b58d81b53531b019745 /source
parent04e445ccfb2a8c52f5f9128e2752df1d7d2358ce (diff)
UI: File Browser Use Friendly Relative Dates
Show 'Today' or 'Yesterday' in file list
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_fileops.h2
-rw-r--r--source/blender/blenlib/intern/BLI_filelist.c40
-rw-r--r--source/blender/editors/space_file/file_draw.c4
3 files changed, 37 insertions, 9 deletions
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;