Add more nil checks to metav1.Time and MicroTime
Co-authored-by: Ben Fuller <bfuller@pivotal.io>
This commit is contained in:
		@@ -41,11 +41,6 @@ func (t *MicroTime) DeepCopyInto(out *MicroTime) {
 | 
				
			|||||||
	*out = *t
 | 
						*out = *t
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// String returns the representation of the time.
 | 
					 | 
				
			||||||
func (t MicroTime) String() string {
 | 
					 | 
				
			||||||
	return t.Time.String()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// NewMicroTime returns a wrapped instance of the provided time
 | 
					// NewMicroTime returns a wrapped instance of the provided time
 | 
				
			||||||
func NewMicroTime(time time.Time) MicroTime {
 | 
					func NewMicroTime(time time.Time) MicroTime {
 | 
				
			||||||
	return MicroTime{time}
 | 
						return MicroTime{time}
 | 
				
			||||||
@@ -72,22 +67,40 @@ func (t *MicroTime) IsZero() bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Before reports whether the time instant t is before u.
 | 
					// Before reports whether the time instant t is before u.
 | 
				
			||||||
func (t *MicroTime) Before(u *MicroTime) bool {
 | 
					func (t *MicroTime) Before(u *MicroTime) bool {
 | 
				
			||||||
 | 
						if t != nil && u != nil {
 | 
				
			||||||
		return t.Time.Before(u.Time)
 | 
							return t.Time.Before(u.Time)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Equal reports whether the time instant t is equal to u.
 | 
					// Equal reports whether the time instant t is equal to u.
 | 
				
			||||||
func (t *MicroTime) Equal(u *MicroTime) bool {
 | 
					func (t *MicroTime) Equal(u *MicroTime) bool {
 | 
				
			||||||
 | 
						if t == nil && u == nil {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if t != nil && u != nil {
 | 
				
			||||||
		return t.Time.Equal(u.Time)
 | 
							return t.Time.Equal(u.Time)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// BeforeTime reports whether the time instant t is before second-lever precision u.
 | 
					// BeforeTime reports whether the time instant t is before second-lever precision u.
 | 
				
			||||||
func (t *MicroTime) BeforeTime(u *Time) bool {
 | 
					func (t *MicroTime) BeforeTime(u *Time) bool {
 | 
				
			||||||
 | 
						if t != nil && u != nil {
 | 
				
			||||||
		return t.Time.Before(u.Time)
 | 
							return t.Time.Before(u.Time)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// EqualTime reports whether the time instant t is equal to second-lever precision u.
 | 
					// EqualTime reports whether the time instant t is equal to second-lever precision u.
 | 
				
			||||||
func (t *MicroTime) EqualTime(u *Time) bool {
 | 
					func (t *MicroTime) EqualTime(u *Time) bool {
 | 
				
			||||||
 | 
						if t == nil && u == nil {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if t != nil && u != nil {
 | 
				
			||||||
		return t.Time.Equal(u.Time)
 | 
							return t.Time.Equal(u.Time)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UnixMicro returns the local time corresponding to the given Unix time
 | 
					// UnixMicro returns the local time corresponding to the given Unix time
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,11 +41,6 @@ func (t *Time) DeepCopyInto(out *Time) {
 | 
				
			|||||||
	*out = *t
 | 
						*out = *t
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// String returns the representation of the time.
 | 
					 | 
				
			||||||
func (t Time) String() string {
 | 
					 | 
				
			||||||
	return t.Time.String()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// NewTime returns a wrapped instance of the provided time
 | 
					// NewTime returns a wrapped instance of the provided time
 | 
				
			||||||
func NewTime(time time.Time) Time {
 | 
					func NewTime(time time.Time) Time {
 | 
				
			||||||
	return Time{time}
 | 
						return Time{time}
 | 
				
			||||||
@@ -72,7 +67,10 @@ func (t *Time) IsZero() bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Before reports whether the time instant t is before u.
 | 
					// Before reports whether the time instant t is before u.
 | 
				
			||||||
func (t *Time) Before(u *Time) bool {
 | 
					func (t *Time) Before(u *Time) bool {
 | 
				
			||||||
 | 
						if t != nil && u != nil {
 | 
				
			||||||
		return t.Time.Before(u.Time)
 | 
							return t.Time.Before(u.Time)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Equal reports whether the time instant t is equal to u.
 | 
					// Equal reports whether the time instant t is equal to u.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user