timetable-extension #1
@ -10,13 +10,8 @@ import (
 | 
			
		||||
 | 
			
		||||
// Fetches the day string for the provided date.
 | 
			
		||||
func getDayString(t time.Time) string {
 | 
			
		||||
	london, err := time.LoadLocation("Europe/London")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("Unable to load time zone info", zap.Error(err))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	timeNow := t.In(london)
 | 
			
		||||
	day := timeNow.Weekday()
 | 
			
		||||
	time := t.In(londonTimezone)
 | 
			
		||||
	day := time.Weekday()
 | 
			
		||||
 | 
			
		||||
	dayStrings := [...]string{"sun", "mon", "tue", "wed", "thu", "fri", "sat"}
 | 
			
		||||
 | 
			
		||||
@ -44,7 +39,6 @@ func isSameToday(t time.Time) bool {
 | 
			
		||||
 | 
			
		||||
// Returns how many days ago `t` was compared to today
 | 
			
		||||
func howManyDaysAgo(t time.Time) int {
 | 
			
		||||
	log.Debug("Calculating how many days ago", zap.Time("Input time", t))
 | 
			
		||||
	// Truncate both times to midnight in UTC timezone
 | 
			
		||||
	today := time.Now().UTC().Truncate(24 * time.Hour)
 | 
			
		||||
	input := t.UTC().Truncate(24 * time.Hour)
 | 
			
		||||
@ -89,7 +83,7 @@ func ParseCifDate(input *string, startOrEnd string) time.Time {
 | 
			
		||||
		return time.Time{}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return t
 | 
			
		||||
	return t.UTC()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Parses CIF days_run field and converts to array of day strings
 | 
			
		||||
 | 
			
		||||
@ -103,6 +103,8 @@ func TestParseCifDate(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	for _, tc := range testCases {
 | 
			
		||||
		result := ParseCifDate(&tc.dateString, tc.startOrEnd)
 | 
			
		||||
		result = result.In(londonTimezone)
 | 
			
		||||
		//fmt.Println(tc.dateString, "|UTC: ", result.In(time.UTC), "|EU/Lon: ", result)
 | 
			
		||||
		if result != tc.expect {
 | 
			
		||||
			t.Errorf("For datestring %s, startOrEnd %s, expected %s, but got %s", tc.dateString, tc.startOrEnd, tc.expect.Format(layout), result.Format(layout))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user