From 7071a211b33bf7b2b1e9b4841ab8feabd487fb84 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Wed, 8 Feb 2017 08:34:04 +0100 Subject: [PATCH] Centralization of duration format and constant for the date format --- main.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 697264e..918f106 100644 --- a/main.go +++ b/main.go @@ -69,8 +69,11 @@ var ( } // Some random string, random for each request oauthStateString = "random" - cfgFilePath = flag.String("config", "configuration.toml", "Path to the configuration file.") - cacheDBPath = flag.String("cache", "cache.db", "Path to the cache sqlite database.") + + defaultDateFormat = "_2 Jan 2006, 15:04" + + cfgFilePath = flag.String("config", "configuration.toml", "Path to the configuration file.") + cacheDBPath = flag.String("cache", "cache.db", "Path to the cache sqlite database.") ) var ctx = context.Background() @@ -205,18 +208,24 @@ func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) { continue } - fmt.Printf("% 35s - L%d - %s to %s (% 4dd %02d:%02d)\n", + fmt.Printf("% 35s - L%d - %s to %s (%s)\n", name, *skill.FinishedLevel, - time.Time(skill.StartDate).Format("_2 Jan 2006, 15:04"), - time.Time(skill.FinishDate).Format("_2 Jan 2006, 15:04"), - int32(duration.Hours())/24, - int32(duration.Minutes())/60%24, - int32(duration.Minutes())%60, + time.Time(skill.StartDate).Format(defaultDateFormat), + time.Time(skill.FinishDate).Format(defaultDateFormat), + formatDuration(duration), ) } } +func formatDuration(duration time.Duration) string { + days := int32(duration.Hours()) / 24 + hours := int32(duration.Minutes()) / 60 % 24 + minutes := int32(duration.Minutes()) % 60 + + return fmt.Sprintf("% 4dd %02d:%02d", days, hours, minutes) +} + func printCharacterInformation(swaggerclient *ESI.App, m *Character) { callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams() callParam.WithCharacterID(m.CharacterID) @@ -330,7 +339,7 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { solarSystemInfo.SolarSystemName, *planet.PlanetType, *planet.UpgradeLevel, *planet.NumPins, - time.Time(*planet.LastUpdate).Format("_2 Jan 2006, 15:04"), + time.Time(*planet.LastUpdate).Format(defaultDateFormat), ) pesiresponse, pesierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil) @@ -362,16 +371,14 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { duration = time.Time(pin.ExpiryTime).Sub(now) } - fmt.Printf(" %s Extractor % 5ds cycle, %s, % 6d per cycle, %s %s (%02dd%02d:%02d)\n", + fmt.Printf(" %s Extractor % 5ds cycle, %s, % 6d per cycle, %s %s (%s)\n", status, *pin.ExtractorDetails.CycleTime, pinNames[*pin.ExtractorDetails.ProductTypeID], *pin.ExtractorDetails.QtyPerCycle, statuscomment, - time.Time(pin.ExpiryTime).Format("_2 Jan 2006, 15:04"), - (int32(duration.Minutes()) / (60 * 24)), - (int32(duration.Minutes())/60)%24, - (int32(duration.Minutes()) % 60), + time.Time(pin.ExpiryTime).Format(defaultDateFormat), + formatDuration(duration), ) } else if pin.SchematicID != 0 {