new format for tabular display of timestamps (#793)
This commit is contained in:
parent
a226035c23
commit
964a2fc39e
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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{}
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user