func (*userFriendlyDurationSuite) TestFormat(c *gc.C) { // lp:1558657 now := time.Now() for _, test := range []struct { other time.Time expected string }{ { other: now, expected: "just now", }, { other: now.Add(-1 * time.Second), expected: "just now", }, { other: now.Add(-2 * time.Second), expected: "2 seconds ago", }, { other: now.Add(-59 * time.Second), expected: "59 seconds ago", }, { other: now.Add(-60 * time.Second), expected: "1 minute ago", }, { other: now.Add(-61 * time.Second), expected: "1 minute ago", }, { other: now.Add(-2 * time.Minute), expected: "2 minutes ago", }, { other: now.Add(-59 * time.Minute), expected: "59 minutes ago", }, { other: now.Add(-60 * time.Minute), expected: "1 hour ago", }, { other: now.Add(-61 * time.Minute), expected: "1 hour ago", }, { other: now.Add(-2 * time.Hour), expected: "2 hours ago", }, { other: now.Add(-23 * time.Hour), expected: "23 hours ago", }, { other: now.Add(-24 * time.Hour), expected: now.Add(-24 * time.Hour).Format("2006-01-02"), }, { other: now.Add(-96 * time.Hour), expected: now.Add(-96 * time.Hour).Format("2006-01-02"), }, } { obtained := common.UserFriendlyDuration(test.other, now) c.Check(obtained, gc.Equals, test.expected) } }
func (c *infoCommandBase) apiUsersToUserInfoSlice(users []params.UserInfo) []UserInfo { var output []UserInfo var now = time.Now() for _, info := range users { outInfo := UserInfo{ Username: info.Username, DisplayName: info.DisplayName, Disabled: info.Disabled, LastConnection: common.LastConnection(info.LastConnection, now, c.exactTime), } if c.exactTime { outInfo.DateCreated = info.DateCreated.String() } else { outInfo.DateCreated = common.UserFriendlyDuration(info.DateCreated, now) } output = append(output, outInfo) } return output }
func (c *infoCommandBase) apiUsersToUserInfoSlice(users []params.UserInfo) []UserInfo { var output []UserInfo var now = c.clock.Now() for _, info := range users { outInfo := UserInfo{ Username: info.Username, DisplayName: info.DisplayName, Access: info.Access, Disabled: info.Disabled, } // TODO(wallyworld) record login information about external users. if names.NewUserTag(info.Username).IsLocal() { outInfo.LastConnection = common.LastConnection(info.LastConnection, now, c.exactTime) if c.exactTime { outInfo.DateCreated = info.DateCreated.String() } else { outInfo.DateCreated = common.UserFriendlyDuration(info.DateCreated, now) } } output = append(output, outInfo) } return output }