From 964a2fc39e4e46c878269f51cab777f1db75fa05 Mon Sep 17 00:00:00 2001 From: Keepers Date: Fri, 9 Sep 2022 20:43:18 -0600 Subject: [PATCH] new format for tabular display of timestamps (#793) --- src/internal/common/time.go | 16 ++++++++++++---- src/internal/common/time_test.go | 7 +++++++ src/pkg/backup/backup.go | 2 +- src/pkg/backup/backup_test.go | 2 +- src/pkg/backup/details/details.go | 9 +++++++-- src/pkg/backup/details/details_test.go | 2 +- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/internal/common/time.go b/src/internal/common/time.go index a5f068ab6..7b58744b2 100644 --- a/src/internal/common/time.go +++ b/src/internal/common/time.go @@ -6,9 +6,10 @@ import ( ) const ( - StandardTimeFormat = time.RFC3339Nano - SimpleDateTimeFormat = "02-Jan-2006_15:04:05" - LegacyFormat = time.RFC3339 + LegacyTimeFormat = time.RFC3339 + SimpleDateTimeFormat = "02-Jan-2006_15:04:05" + StandardTimeFormat = time.RFC3339Nano + TabularOutputTimeFormat = "2006-01-02T15:04:05Z" ) // FormatNow produces the current time in UTC using the provided @@ -29,10 +30,17 @@ func FormatSimpleDateTime(t time.Time) string { return t.UTC().Format(SimpleDateTimeFormat) } +// FormatTabularDisplayTime produces the standard format for displaying +// a timestamp as part of user-readable cli output. +// "2016-01-02T15:04:05Z" +func FormatTabularDisplayTime(t time.Time) string { + return t.UTC().Format(TabularOutputTimeFormat) +} + // FormatLegacyTime produces standard format for string values // that are placed in SingleValueExtendedProperty tags func FormatLegacyTime(t time.Time) string { - return t.UTC().Format(LegacyFormat) + return t.UTC().Format(LegacyTimeFormat) } // ParseTime makes a best attempt to produce a time value from diff --git a/src/internal/common/time_test.go b/src/internal/common/time_test.go index dd0c5c758..5c7341778 100644 --- a/src/internal/common/time_test.go +++ b/src/internal/common/time_test.go @@ -33,6 +33,13 @@ func (suite *CommonTimeUnitSuite) TestLegacyTime() { assert.Equal(t, now.UTC().Format(time.RFC3339), result) } +func (suite *CommonTimeUnitSuite) TestFormatTabularDisplayTime() { + t := suite.T() + now := time.Now() + result := common.FormatTabularDisplayTime(now) + assert.Equal(t, now.UTC().Format(common.TabularOutputTimeFormat), result) +} + func (suite *CommonTimeUnitSuite) TestParseTime() { t := suite.T() now := time.Now() diff --git a/src/pkg/backup/backup.go b/src/pkg/backup/backup.go index f6f8589f3..430faf44e 100644 --- a/src/pkg/backup/backup.go +++ b/src/pkg/backup/backup.go @@ -114,7 +114,7 @@ func (b Backup) Values() []string { status := fmt.Sprintf("%s (%d errors)", b.Status, errCount) return []string{ - common.FormatTime(b.StartedAt), + common.FormatTabularDisplayTime(b.StartedAt), string(b.ID), status, b.Selectors.ToPrintable().Resources(), diff --git a/src/pkg/backup/backup_test.go b/src/pkg/backup/backup_test.go index 4acf39c6c..a295bb299 100644 --- a/src/pkg/backup/backup_test.go +++ b/src/pkg/backup/backup_test.go @@ -64,7 +64,7 @@ func (suite *BackupSuite) TestBackup_HeadersValues() { hs := b.Headers() assert.Equal(t, expectHs, hs) - nowFmt := common.FormatTime(now) + nowFmt := common.FormatTabularDisplayTime(now) expectVs := []string{ nowFmt, "id", diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index 181e36e83..5eb1c6466 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -234,13 +234,18 @@ func (i ExchangeInfo) Headers() []string { func (i ExchangeInfo) Values() []string { switch i.ItemType { case ExchangeEvent: - return []string{i.Organizer, i.Subject, common.FormatTime(i.EventStart), strconv.FormatBool(i.EventRecurs)} + return []string{ + i.Organizer, + i.Subject, + common.FormatTabularDisplayTime(i.EventStart), + strconv.FormatBool(i.EventRecurs), + } case ExchangeContact: return []string{i.ContactName} case ExchangeMail: - return []string{i.Sender, i.Subject, common.FormatTime(i.Received)} + return []string{i.Sender, i.Subject, common.FormatTabularDisplayTime(i.Received)} } return []string{} diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index 2084d168c..7b3d8c326 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -24,7 +24,7 @@ func TestDetailsUnitSuite(t *testing.T) { } func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { - nowStr := common.FormatNow(common.StandardTimeFormat) + nowStr := common.FormatNow(common.TabularOutputTimeFormat) now, err := common.ParseTime(nowStr) require.NoError(suite.T(), err)