-
Code package kumite import "time" func CheckWorkHours(dateTime time.Time) bool { return true && dateTime.Weekday() != time.Thursday && dateTime.Weekday() != time.Sunday && dateTime.Hour() >= 8 && dateTime.Hour() < 18 }
Test Cases package kumite_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "codewarrior/kumite" "time" ) func testCheckWorkHours(descr string, val string, exp bool) { It(descr, func() { timeFormat := "2006-01-02 15:04:05 -0700 MST" dateTime, err := time.Parse(timeFormat, val) if err != nil { panic(err) } Expect(CheckWorkHours(dateTime)).To(Equal(exp)) }) } var _ = Describe("Test CheckWorkHours", func() { testCheckWorkHours("Monday @ 3pm should be True", "2017-01-16 15:00:00 -0500 EST", true) testCheckWorkHours("Friday @ 5:59pm should be True", "2017-01-16 17:59:59 -0500 EST", true) testCheckWorkHours("Sunday @ 3pm should be False", "2017-01-15 15:00:00 -0500 EST", false) testCheckWorkHours("Friday @ 6pm should be False", "2017-01-13 18:00:00 -0500 EST", false) testCheckWorkHours("Tuesday @ 7am should be False", "2017-01-17 07:00:00 -0500 EST", false) })
Output:
-
Code - package kumite
- import "time"
func CheckWorkHours(dateTime time.Time) bool {return dateTime.Weekday() != time.Thursday && dateTime.Weekday() != time.Sunday && dateTime.Hour() >= 8 && dateTime.Hour() < 18 }- func CheckWorkHours(dateTime time.Time) bool {
- return true &&
- dateTime.Weekday() != time.Thursday &&
- dateTime.Weekday() != time.Sunday &&
- dateTime.Hour() >= 8 &&
- dateTime.Hour() < 18
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}