Centralization of duration format and constant for the date format

This commit is contained in:
Thomas Schwery 2017-02-08 08:34:04 +01:00
parent 1e630fbf2e
commit 7071a211b3

35
main.go
View file

@ -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 {