mirror of
https://github.com/dancojocaru2000/CfrTrainInfoTelegramBot.git
synced 2025-02-22 17:19:39 +02:00
Add message for train that didn't depart yet
This commit is contained in:
parent
365e76b4aa
commit
f7970ff50f
1 changed files with 19 additions and 6 deletions
|
@ -182,7 +182,7 @@ func HandleTrainNumberCommand(ctx context.Context, trainNumber string, date time
|
||||||
}
|
}
|
||||||
messageText.WriteString(fmt.Sprintf("Next stop: %s, arriving in %s at %s\n", nextStop.Name, arrStr, arrTime.In(utils.Location).Format("15:04")))
|
messageText.WriteString(fmt.Sprintf("Next stop: %s, arriving in %s at %s\n", nextStop.Name, arrStr, arrTime.In(utils.Location).Format("15:04")))
|
||||||
} else {
|
} else {
|
||||||
depStr := "less than 1m"
|
depStr := ""
|
||||||
depTime := nextStop.Departure.ScheduleTime.Add(func() time.Duration {
|
depTime := nextStop.Departure.ScheduleTime.Add(func() time.Duration {
|
||||||
if nextStop.Departure.Status != nil {
|
if nextStop.Departure.Status != nil {
|
||||||
return time.Minute * time.Duration(nextStop.Departure.Status.Delay)
|
return time.Minute * time.Duration(nextStop.Departure.Status.Delay)
|
||||||
|
@ -191,12 +191,25 @@ func HandleTrainNumberCommand(ctx context.Context, trainNumber string, date time
|
||||||
}
|
}
|
||||||
}())
|
}())
|
||||||
depDiff := depTime.Sub(time.Now())
|
depDiff := depTime.Sub(time.Now())
|
||||||
if depDiff/time.Hour >= 1 {
|
if depDiff/(time.Hour*24) >= 1 {
|
||||||
depStr = fmt.Sprintf("%dh%dm", depDiff/time.Hour, (depDiff%time.Hour)/time.Minute)
|
depStr += fmt.Sprintf("%dd", depDiff/(time.Hour*24))
|
||||||
} else if depDiff/time.Minute >= 1 {
|
depDiff = depDiff % (time.Hour * 24)
|
||||||
depStr = fmt.Sprintf("%dm", depDiff/time.Minute)
|
}
|
||||||
|
if depDiff/time.Hour >= 1 {
|
||||||
|
depStr += fmt.Sprintf("%dh", depDiff/time.Hour)
|
||||||
|
depDiff = depDiff % time.Hour
|
||||||
|
}
|
||||||
|
if depDiff/time.Minute >= 1 {
|
||||||
|
depStr += fmt.Sprintf("%dm", depDiff/time.Minute)
|
||||||
|
}
|
||||||
|
if len(depStr) == 0 {
|
||||||
|
depStr = "less than 1m"
|
||||||
|
}
|
||||||
|
if nextStopIdx == 0 {
|
||||||
|
messageText.WriteString(fmt.Sprintf("The train will depart from %s in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
||||||
|
} else {
|
||||||
|
messageText.WriteString(fmt.Sprintf("Currently stopped at: %s, departing in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
||||||
}
|
}
|
||||||
messageText.WriteString(fmt.Sprintf("Currently stopped at: %s, departing in %s at %s\n", nextStop.Name, depStr, depTime.In(utils.Location).Format("15:04")))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if group.Status != nil {
|
if group.Status != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue