-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix new jobs showing as failed in dashboard in western timezones
- Loading branch information
Showing
10 changed files
with
385 additions
and
253 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ntime | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
// NullableTime represents a Time from the time package, but can have no value set | ||
type NullableTime struct { | ||
hasValue bool | ||
time time.Time | ||
} | ||
|
||
// HasValue returns whether a time has been set | ||
func (t *NullableTime) HasValue() bool { | ||
return t.hasValue | ||
} | ||
|
||
// Set a time. This is the equivalent of an assignment | ||
func (t *NullableTime) Set(newTime time.Time) { | ||
t.hasValue = true | ||
t.time = newTime | ||
} | ||
|
||
// Unset sets the value to nothing. This is the equivalent of assigning nil. | ||
func (t *NullableTime) Unset() { | ||
t.hasValue = false | ||
} | ||
|
||
// Get returns the contained value. Panics if no value is set. | ||
func (t *NullableTime) Get() time.Time { | ||
if t.hasValue { | ||
return t.time | ||
} | ||
panic("runtime error: attempt to get value of NullableTime set to nil.") | ||
} | ||
|
||
// After determines whether one time is after another. | ||
func (t *NullableTime) After(u NullableTime) bool { | ||
// nil after u? No value is ever after anything else | ||
if !t.hasValue { | ||
return false | ||
} | ||
|
||
// t after nil? Always. | ||
if !u.hasValue { | ||
return true | ||
} | ||
|
||
// t after u? | ||
return t.time.After(u.time) | ||
} | ||
|
||
// MarshalJSON serializer this struct to JSON | ||
// Implements json.Marshaler interface | ||
func (t *NullableTime) MarshalJSON() ([]byte, error) { | ||
if t.hasValue { | ||
return json.Marshal(t.time) | ||
} | ||
return json.Marshal(nil) | ||
} |
Oops, something went wrong.