Author: Paolo Lulli <paolo@lulli.net>
Parse from/to with --date YYYYMMDD
client/main.go | 6 ++++-- client/time-util.go | 13 +++++++++++--
diff --git a/client/main.go b/client/main.go index 1397a849309c42c5365854250f31d0edc43ebd75..9bcd686a253090fe54c8f8858548ea5aad549e87 100644 --- a/client/main.go +++ b/client/main.go @@ -71,6 +71,8 @@ sinceHours := flag.BoolP("hour", "", false, "hours ago") sinceDays := flag.BoolP("day", "", false, "days ago") sinceYears := flag.BoolP("year", "", false, "years ago") + midnightOfDay := flag.BoolP("date", "", false, "midnight of day <YYMMDD>T00:00:00") + reformatOutput := flag.BoolP("format", "f", false, "format output") logOutput := flag.BoolP("value-only", "l", false, "log value only output") decodeBase64Output := flag.BoolP("base64-decode", "b", false, "decode base64 output") @@ -82,13 +84,13 @@ var fromTimestamp int64 var toTimestamp int64 if *fromOption != 0 { - fromTimestamp = calculateCutDate(*fromOption, sinceSeconds, sinceMinutes, sinceHours, sinceDays, sinceYears) + fromTimestamp = calculateCutDate(*fromOption, sinceSeconds, sinceMinutes, sinceHours, sinceDays, sinceYears, midnightOfDay) } else { fromTimestamp = 0 } if *toOption != 0 { - toTimestamp = calculateCutDate(*toOption, sinceSeconds, sinceMinutes, sinceHours, sinceDays, sinceYears) + toTimestamp = calculateCutDate(*toOption, sinceSeconds, sinceMinutes, sinceHours, sinceDays, sinceYears, midnightOfDay) } else { toTimestamp = 0 } diff --git a/client/time-util.go b/client/time-util.go index 3d4b2390fa1bf43c6f9b1261e734808caf4c9d7f..2e507ff64a28bbdf1a461ff34c09cb8f4281dac8 100644 --- a/client/time-util.go +++ b/client/time-util.go @@ -9,14 +9,17 @@ * @copyright Paolo Lulli 2024 */ package main -import "time" +import ( + "fmt" + "time" +) func formattedUtcTimeInSec(int64Ts int64) string { unixTimeUTC := time.UnixMilli(int64Ts) return unixTimeUTC.Format(time.RFC3339) } -func calculateCutDate(ts int64, sinceSeconds *bool, sinceMinutes *bool, sinceHours *bool, sinceDays *bool, sinceYears *bool) int64 { +func calculateCutDate(ts int64, sinceSeconds *bool, sinceMinutes *bool, sinceHours *bool, sinceDays *bool, sinceYears *bool, midnightOfDay *bool) int64 { if 0 != ts { if *sinceSeconds { return time.Now().Unix() - ts @@ -32,6 +35,12 @@ return time.Now().Unix() - ts*60*60*24 } if *sinceYears { return time.Now().Unix() - ts*60*60*24*365 + } + if *midnightOfDay { + timeString := fmt.Sprintf("%d", ts) + YYYYMMDD := "20060102" + t, _ := time.Parse(YYYYMMDD, timeString) + return t.Unix() } } return ts