In my Go application, I am trying to check the occurrence of a date in a period.
if survey.StartPeriod.Before(time.Now()) && survey.EndPeriod.After(time.Now()) {
fmt.Println("1 BLOCK")
}
else if survey.EndPeriod.Before(time.Now()) {
fmt.Println("2 BLOCK")
}
If I have such incoming data (current time inside period):
Current TIME | 2019-03-28 21:02:47.0377305 +0600 +06 m=+60.748044601
START_PERIOD | 2019-03-28 21:00:00 +0000 +0000
END_PERIOD | 2019-03-28 21:05:00 +0000 +0000
I want to run code inside 1 block. My current code run that block only if I use Before
function to both periods. I am not sure that it's correct.
If I have such incoming data (current time outside the end_period):
Current TIME | 2019-03-28 21:10:47.0377305 +0600 +06 m=+60.748044601
START_PERIOD | 2019-03-28 21:00:00 +0000 +0000
END_PERIOD | 2019-03-28 21:05:00 +0000 +0000
I want to run code inside 2 block. Right know it works incorrect. How to correctly make this program logic?
EDIT:
As you can see CURRENT_TIME
inside range.
CURRENT_TIME | 2019-03-29 08:32:06.1375323 +0600 +06 m=+60.318452301
START_PERIOD | 2019-03-29 08:30:00 +0000 +0000
END_PERIOD | 2019-03-29 08:31:00 +0000 +0000
When I try to test function InTimeSpan
it return false
value which is not correct. I am really confused. Why it happens?!
log.Println(InTimeSpan(survey.StartPeriod, survey.EndPeriod, time.Now()))
// return false