mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-01 11:12:15 +00:00
Update TS + date format
This commit is contained in:
parent
cbd230fdc4
commit
4c2b18f40c
2 changed files with 31 additions and 10 deletions
|
@ -1,8 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 1.2
|
||||
- Change lastUpdated to pointer reference
|
||||
- Change lastUpdated to pointer reference and use built in .After() functions
|
||||
- Change date format to support multiple dates in single point of interest
|
||||
- Update lastUpdated to max of previous event
|
||||
|
||||
## 1.1
|
||||
- Split messages based on location
|
||||
|
|
|
@ -79,10 +79,9 @@ func fetchAPILocations() (ApiResponse, error) {
|
|||
|
||||
// getNewAPILocations - Gets all locations and triggers posts
|
||||
func getNewAPILocations() {
|
||||
// Set lastUpdate time at the start of the request so we don't miss any locations
|
||||
// posted right after we poll
|
||||
newPollTime := time.Now()
|
||||
previousPollTime := *lastUpdated
|
||||
// Set lastUpdated to the
|
||||
previousUpdatedTime := *lastUpdated
|
||||
newUpdatedTime := *lastUpdated
|
||||
|
||||
// Pull latest data
|
||||
locations, err := fetchAPILocations()
|
||||
|
@ -96,10 +95,15 @@ func getNewAPILocations() {
|
|||
|
||||
// Iterate over the data and only find new locations
|
||||
for _, item := range locations.Items {
|
||||
if item.PublishedAt.Unix() > previousPollTime.Unix() {
|
||||
if item.PublishedAt.After(previousUpdatedTime) {
|
||||
// Clone the item to put in our own lil slice
|
||||
copy := item
|
||||
newItems[item.Location.City] = append(newItems[item.Location.City], copy)
|
||||
|
||||
// Always keep the latest
|
||||
if item.PublishedAt.After(newUpdatedTime) {
|
||||
newUpdatedTime = item.PublishedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +126,10 @@ func getNewAPILocations() {
|
|||
postTheUpdates()
|
||||
}
|
||||
|
||||
updateLastUpdated(&newPollTime)
|
||||
// Only update the time if greater!
|
||||
if newUpdatedTime.After(previousUpdatedTime) {
|
||||
updateLastUpdated(&newUpdatedTime)
|
||||
}
|
||||
}
|
||||
|
||||
// updateLastUpdated - Creates/Updates lastUpdated.txt
|
||||
|
@ -156,8 +163,21 @@ func (item ApiItem) getDateString() string {
|
|||
st := item.StartDateTime
|
||||
et := item.EndDateTime
|
||||
|
||||
dateFormat := "Mon Jan 2nd 3:04PM"
|
||||
timeFormat := "2nd 3:04PM"
|
||||
std := getDaySuffix(st)
|
||||
|
||||
return st.Local().Format(dateFormat) + " - " + et.Local().Format(timeFormat)
|
||||
return st.Local().Format("Jan 2"+std+" Mon 3:04PM") + " - " + et.Local().Format("Mon 3:04PM")
|
||||
}
|
||||
|
||||
// getDaySuffix - get day suffix
|
||||
func getDaySuffix(t time.Time) string {
|
||||
suffix := "th"
|
||||
switch t.Day() {
|
||||
case 1, 21, 31:
|
||||
suffix = "st"
|
||||
case 2, 22:
|
||||
suffix = "nd"
|
||||
case 3, 23:
|
||||
suffix = "rd"
|
||||
}
|
||||
return suffix
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue