Changing routine from year to date

This routine currently checks if the task ‘year’ is in the future of the current ‘year’. Can anyone help me change it so that it checks if the task ‘date’ is in the future of the current ‘date’. I’m guessing the ‘year’ needs changing but I’m unsure what to (not as simple as ‘data’ is it lol)!

var currentDateTime = time.Now()

taskExpirationDate, _ := time.Parse("2009-01-02", tokens[4])

if taskExpirationDate.Year() > currentDateTime.Year() {
	return TaskResponseRegistered
}

return TaskResponsePending

It could be something like

func IsInFuture(taskExpirationDate Time) bool {
   result := false
   currentDateTime := time.Now()

    if (taskExpirationDate.Year() > currentDateTime.Year()) {
    result = true
  } 

 if (taskExpirationDate.Year() == currentDateTime.Year() && 
     taskExpirationDate.Month() > currentDateTime.Month()) {
    result = true
 }   

 if (taskExpirationDate.Year() == currentDateTime.Year() && 
     taskExpirationDate.Month() == currentDateTime.Month() && 
      taskExpirationDate.Day() > currentDateTime.DayMonth()) {
   result = true
 }

 return result;

}

Have a quick look at https://golang.org/pkg/time/#Time.After

1 Like

time.Time has a method After:

After reports whether the time instant t is after u.

1 Like

Everyday i learn more from this group!!!
I did not aware about this function.
Thanks!!!

1 Like

Thank you, though unfortunately I have no idea how I’d integrate that method into my existing code without changing too much. Any pointers appreciated.

You can change it so it looks kinda like:

var currentDateTime = time.Now()

taskExpirationDate, _ := time.Parse("2006-01-02", tokens[4])

if taskExpirationDate.After(currentDateTime) {
	return TaskResponseRegistered
}
return TaskResponsePending
1 Like

Thank you so much, that did the trick :smiley:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.