Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve nil receiver handling for package gtime #2226

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/gf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Start Apollo Containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build

- name: Start Redis Cluster Containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" up -d --build

- name: Start Minikube
uses: medyagh/setup-minikube@master

Expand All @@ -161,22 +167,16 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-

- name: Start redis cluster containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" up -d --build

- name: Start apollo containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build

- name: Before Script
run: bash .github/workflows/before_script.sh

- name: Build & Test
run: bash .github/workflows/build_and_test.sh

- name: Stop redis cluster containers
- name: Stop Redis Cluster Containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" down

- name: Stop apollo containers
- name: Stop Apollo Containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" down

- name: Report Coverage
Expand Down
23 changes: 21 additions & 2 deletions os/gtime/gtime_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,16 @@ func (t *Time) Truncate(d time.Duration) *Time {
// See the documentation on the Time type for the pitfalls of using == with
// Time values; most code should use Equal instead.
func (t *Time) Equal(u *Time) bool {
return t.Time.Equal(u.Time)
switch {
case t == nil && u != nil:
return false
case t == nil && u == nil:
return true
case t != nil && u == nil:
return false
default:
return t.Time.Equal(u.Time)
}
}

// Before reports whether the time instant t is before u.
Expand All @@ -327,14 +336,24 @@ func (t *Time) Before(u *Time) bool {

// After reports whether the time instant t is after u.
func (t *Time) After(u *Time) bool {
return t.Time.After(u.Time)
switch {
case t == nil:
return false
case t != nil && u == nil:
return true
default:
return t.Time.After(u.Time)
}
}

// Sub returns the duration t-u. If the result exceeds the maximum (or minimum)
// value that can be stored in a Duration, the maximum (or minimum) duration
// will be returned.
// To compute t-d for a duration d, use t.Add(-d).
func (t *Time) Sub(u *Time) time.Duration {
if t == nil || u == nil {
return 0
}
return t.Time.Sub(u.Time)
}

Expand Down