Computer scienceProgramming languagesGolangPackages and modulesStandard libraryTime package

Parsing and formatting time

Friday

Report a typo

At the beginning of the week, we all dream that Friday would come as soon as possible. Let's find out how much time is left until the next Friday! Rather until 16 o'clock next Friday.

As input, you'll get a string with a date and time in RFC3339 format. You need to print out one of the next messages:

  • Relax! It's a weekend day! — if it's Saturday or Sunday;
  • Working week is over! — if it's Friday, but after 16 o'clock;
  • It's %d hours and %d minutes until the next Friday! — if the working week is in full swing.

Tip: Standard layouts of time are included in a time package, for example: time.RFC3339.

Sample Input 1:

2006-05-12T00:00:00-00:00

Sample Output 1:

It's 16 hours and 0 minutes until the next Friday!
Write a program in Go
package main

import (
"fmt"
"log"
"time"
)

const (
HoursPerDay = 24
MinutesPerHour = 60
)

// DO NOT modify the getFridayDate function:
func getFridayDate(currentDate time.Time) time.Time {
fridayDate := time.Date(
currentDate.Year(),
currentDate.Month(),
currentDate.Day(),
16, 0, 0, 0,
currentDate.Location(),
)

for fridayDate.Weekday() != time.Friday {
fridayDate = fridayDate.Add(time.Hour * HoursPerDay)
}
return fridayDate
}

// Write the additional code below to find if it's Saturday or Sunday
func isWeekend(currentDate time.Time) bool {
return currentDate.?() == time.? || currentDate.?() == ?
}

// Write the additional code below to find if it's Friday after 16:00
func isFridayAfternoon(currentDate time.Time) bool {
___

Create a free account to access the full topic