(from bug #867376 comment #8) There's probably one more thing to cover - date/time fields (e.g. lv creation time). Currently, these fields are recognized as strings which means the comparison is done simply on strings. It would be nice, if we could add a separate field type "DM_REPORT_FIELD_TYPE_DATE_TIME" and then we should be able to compare the date and time formats. I envision this to be very similar to what "git" command has, e.g. 'git log --since "two weeks ago"' - this would look like in LVM: 'lvs --select time < "two weeks"'. Or maybe a new time-comparing operator for this (like since, before...). But this is not high prio at all. Let's have a look at this if there's some spare time. Maybe lots of this code can be just reused: https://github.com/git/git/blob/master/date.c.
This bug is about extending reporting code to support time values and also to support time expressions for selection criteria (the -S/--select option). Currently, there's only one reporting field which displays time. Before these changes, it was internally represented as string value only which did not allow more advanced matching when such field was used in selection criteria. Before, either the whole string matched or it matched regex. Also we couldn't define time in more natural way (e.g. yesterday, 3 weeks ago...) and we couldn't define time ranges. We have extended support for time values in reporting and selection code so time is now properly recognized. For better readability of selection expressions, we have also added aliases for comparison operators that can be used with time values: "since" as an alias for ">=" "after" as an alias for ">" "until" as an alias for "<=" "before" as an alias for "<" There are two basic ways how to define time so that LVM recognizes it: === A) Subset of strict stanardized format (subset of ISO 8601) which is directly recognized in libdevmapper for new DM_REPORT_FIELD_TYPE_TIME type: date time timezone date: YYYY-MM-DD (or shortly YYYYMMDD) YYYY-MM (shortly YYYYMM), auto DD=1 YYYY, auto MM=01 and DD=01 time: hh:mm:ss (or shortly hhmmss) hh:mm (or shortly hhmm), auto ss=0 hh (or shortly hh), auto mm=0, auto ss=0 timezone (always with + or - sign): +hh:mm or -hh:mm (or shortly +hhmm or -hhmm) +hh or -hh (No support for timezone names here as they may be ambiguous!) Note: The full date/time specification is YYYY-MM-DD hh:mm:ss. Users are able to leave date/time parts from right to left. Whenever these parts are left out, a range is assumed automatically with second granularity. For example: "2015-07-07 9:51" means range of "2015-07-07 9:51:00" - "2015-07-07 9:51:59" "2015-07" means range of "2015-07-01 0:00:00" - "2015-07-31 23:59:59" "2015" means range of "2015-01-01 0:00:00" - "2015-12-31 23:59:59" ... When used in selection criteria: lvs -S 'time since "2015-07-07 9:51"' lvs -S 'time = "2015-07"" lvs -S 'time = "2015"' ... === B) An extension for date/time recognition (currently for the lv_time field only) which allows more free-form specification and it can be combined with these entities: - weekday names ("Sunday" - "Saturday" or abbreviated as "Sun" - "Sat") - labels for points in time ("noon", "midnight") - labels for a day relative to current day ("today", "yesterday") - points back in time with relative offset from today (N is a number) ( "N" "seconds"/"minutes"/"hours"/"days"/"weeks"/"years" "ago") ( "N" "secs"/"mins"/"hrs" ... "ago") ( "N" "s"/"m"/"h" ... "ago") - time specification either in hh:mm:ss format or with AM/PM suffixes - month names ("January" - "December" or abbreviated as "Jan" - "Dec") For example: lvs -S 'time since "yesterday 9AM"' lvs -S 'time since "Feb 3 years 2 months ago"' lvs -S 'time = "February 2015"' lvs -S 'time since "Jan 15 2015" && time until yesterday' lvs -S 'time since "today 6AM"' ...and lots of other combinations from the set above (LVM will error out with a proper error message pointing to the problematic part if time was not recognized properly or if it finds the time expression ambiguous). ======= We have also provided new report/time_format lvm.conf option with which it's possible to define the way the time is displayed for time reporting fields. The format is described in lvm.conf comments (it's actually a restricted subset of formatting sequences which is also known from strftime function [man 3 strftime] and date command [man 1 date]). For example: $ lvmconfig --type full report/time_format time_format="%a %Y-%m-%d %T %z %Z [%s]" $lvs -o name,time vg/lvol1 LV Time lvol1 Tue 2015-07-07 09:25:24 +0200 CEST [1436253924]