diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index af579f93f..f69ed36e7 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -125,7 +125,8 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT); bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT); - uint64_t duration = ffTimeGetNow() - disk->createTime; + uint64_t now = ffTimeGetNow(); + uint64_t duration = now - disk->createTime; uint32_t milliseconds = (uint32_t) (duration % 1000); duration /= 1000; uint32_t seconds = (uint32_t) (duration % 60); @@ -136,6 +137,33 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index duration /= 24; uint32_t days = (uint32_t) duration; + time_t past_s = (time_t) (disk->createTime / 1000); + struct tm past_tm; + #ifdef _WIN32 + localtime_s(&past_tm, &past_s); + #else + localtime_r(&past_s, &past_tm); + #endif + + time_t now_s = (time_t) (now / 1000); + struct tm now_tm; + #ifdef _WIN32 + localtime_s(&now_tm, &now_s); + #else + localtime_r(&now_s, &now_tm); + #endif + + uint32_t years = (uint32_t) (now_tm.tm_year - past_tm.tm_year); + if (now_tm.tm_yday < past_tm.tm_yday) + years--; + past_tm.tm_year += years; + uint32_t gap_s = (uint32_t) (now_s - mktime(&past_tm)); + uint32_t daysOfYear = gap_s / (24 * 60 * 60); + + uint32_t pastYear = past_tm.tm_year + 1900; + bool isLeapYear = (pastYear % 4 == 0 && pastYear % 100 != 0) || (pastYear % 400 == 0); + double yearsFraction = (double) daysOfYear / (isLeapYear ? 366 : 365) + years; + FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]) { FF_FORMAT_ARG(usedPretty, "size-used"), FF_FORMAT_ARG(totalPretty, "size-total"), @@ -158,6 +186,9 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index FF_FORMAT_ARG(milliseconds, "milliseconds"), FF_FORMAT_ARG(disk->mountpoint, "mountpoint"), FF_FORMAT_ARG(disk->mountFrom, "mount-from"), + FF_FORMAT_ARG(years, "years"), + FF_FORMAT_ARG(daysOfYear, "days-of-year"), + FF_FORMAT_ARG(yearsFraction, "years-fraction"), })); } } @@ -523,6 +554,9 @@ static FFModuleBaseInfo ffModuleInfo = { {"Milliseconds after creation", "milliseconds"}, {"Mount point / drive letter", "mountpoint"}, {"Mount from (device path)", "mount-from"}, + {"Years integer after creation", "years"}, + {"Days of year after creation", "days-of-year"}, + {"Years fraction after creation", "years-fraction"}, })) };