I'm trying to do this tutorial but with TypeScript, however, I'm not having success with Date calculations, I think I need to study more about it haha.// getBeginningOfDay given a time.Time calculates the start time of that day func getBeginningOfDay(t time.Time) time.Time { year, month, day := t.Date() startOfDay := time.Date(year, month, day, 0, 0, 0, 0, t.Location()) return startOfDay } // countDaysSinceDate counts how many days passed since the passed date func countDaysSinceDate(date time.Time) int { days := 0 now := getBeginningOfDay(time.Now()) for date.Before(now) { date = date.Add(time.Hour * 24) days++ if days > daysInLastSixMonths { return outOfRange } } return days }// printMonths prints the month names in the first line, determining when the month // changed between switching weeks func printMonths() { week := getBeginningOfDay(time.Now()).Add(-(daysInLastSixMonths * time.Hour * 24)) month := week.Month() fmt.Printf(" ") for { if week.Month() != month { fmt.Printf("%s ", week.Month().String()[:3]) month = week.Month() } else { fmt.Printf(" ") } week = week.Add(7 * time.Hour * 24) if week.After(time.Now()) { break } } fmt.Printf("\n") }
Submitted August 16, 2020 at 03:46AM by Mdsp9070
No comments:
Post a Comment