new format for tabular display of timestamps (#793)

This commit is contained in:
Keepers 2022-09-09 20:43:18 -06:00 committed by GitHub
parent a226035c23
commit 964a2fc39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 9 deletions

View File

@ -6,9 +6,10 @@ import (
) )
const ( const (
StandardTimeFormat = time.RFC3339Nano LegacyTimeFormat = time.RFC3339
SimpleDateTimeFormat = "02-Jan-2006_15:04:05" SimpleDateTimeFormat = "02-Jan-2006_15:04:05"
LegacyFormat = time.RFC3339 StandardTimeFormat = time.RFC3339Nano
TabularOutputTimeFormat = "2006-01-02T15:04:05Z"
) )
// FormatNow produces the current time in UTC using the provided // 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) 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 // FormatLegacyTime produces standard format for string values
// that are placed in SingleValueExtendedProperty tags // that are placed in SingleValueExtendedProperty tags
func FormatLegacyTime(t time.Time) string { 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 // ParseTime makes a best attempt to produce a time value from

View File

@ -33,6 +33,13 @@ func (suite *CommonTimeUnitSuite) TestLegacyTime() {
assert.Equal(t, now.UTC().Format(time.RFC3339), result) 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() { func (suite *CommonTimeUnitSuite) TestParseTime() {
t := suite.T() t := suite.T()
now := time.Now() now := time.Now()

View File

@ -114,7 +114,7 @@ func (b Backup) Values() []string {
status := fmt.Sprintf("%s (%d errors)", b.Status, errCount) status := fmt.Sprintf("%s (%d errors)", b.Status, errCount)
return []string{ return []string{
common.FormatTime(b.StartedAt), common.FormatTabularDisplayTime(b.StartedAt),
string(b.ID), string(b.ID),
status, status,
b.Selectors.ToPrintable().Resources(), b.Selectors.ToPrintable().Resources(),

View File

@ -64,7 +64,7 @@ func (suite *BackupSuite) TestBackup_HeadersValues() {
hs := b.Headers() hs := b.Headers()
assert.Equal(t, expectHs, hs) assert.Equal(t, expectHs, hs)
nowFmt := common.FormatTime(now) nowFmt := common.FormatTabularDisplayTime(now)
expectVs := []string{ expectVs := []string{
nowFmt, nowFmt,
"id", "id",

View File

@ -234,13 +234,18 @@ func (i ExchangeInfo) Headers() []string {
func (i ExchangeInfo) Values() []string { func (i ExchangeInfo) Values() []string {
switch i.ItemType { switch i.ItemType {
case ExchangeEvent: 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: case ExchangeContact:
return []string{i.ContactName} return []string{i.ContactName}
case ExchangeMail: case ExchangeMail:
return []string{i.Sender, i.Subject, common.FormatTime(i.Received)} return []string{i.Sender, i.Subject, common.FormatTabularDisplayTime(i.Received)}
} }
return []string{} return []string{}

View File

@ -24,7 +24,7 @@ func TestDetailsUnitSuite(t *testing.T) {
} }
func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
nowStr := common.FormatNow(common.StandardTimeFormat) nowStr := common.FormatNow(common.TabularOutputTimeFormat)
now, err := common.ParseTime(nowStr) now, err := common.ParseTime(nowStr)
require.NoError(suite.T(), err) require.NoError(suite.T(), err)