diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b02a38e..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. -# See: https://circleci.com/docs/2.0/configuration-reference -version: 2.1 - -# Define a job to be invoked later in a workflow. -# See: https://circleci.com/docs/2.0/configuration-reference/#jobs -jobs: - build: - working_directory: ~/repo - # Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub. - # See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor - docker: - - image: circleci/golang:1.18 - # Add steps to the job - # See: https://circleci.com/docs/2.0/configuration-reference/#steps - steps: - - checkout - - restore_cache: - keys: - - go-mod-v4-{{ checksum "go.sum" }} - - run: - name: Install Dependencies - command: go mod download - - save_cache: - key: go-mod-v4-{{ checksum "go.sum" }} - paths: - - "/go/pkg/mod" - - run: - name: Run tests - command: | - mkdir -p /tmp/test-reports - gotestsum --junitfile /tmp/test-reports/unit-tests.xml - - store_test_results: - path: /tmp/test-reports - -# Invoke jobs via workflows -# See: https://circleci.com/docs/2.0/configuration-reference/#workflows -workflows: - sample: # This is the name of the workflow, feel free to change it to better match your workflow. - # Inside the workflow, you define the jobs you want to run. - jobs: - - build \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index 511f0fc..c56c479 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,9 +3,15 @@ type: docker name: clone steps: - - name: test-golang + - name: Test image: golang:1.18 commands: - go env -w GO111MODULE=on - go env -w GOPROXY=https://goproxy.cn,direct - - go test -v ./... \ No newline at end of file + - go test -v ./... + - name: Benchmark + image: golang:1.18 + commands: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - go test -bench=. -benchmem \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 1d4bb34..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: coverage - -on: - push: - branches: [ master ] - paths-ignore: - - '**.md' - pull_request: - branches: [ master ] - paths-ignore: - - '**.md' - -jobs: - test: - name: Test with Coverage - runs-on: ubuntu-latest - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Check out code - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - go mod download - - name: Run Unit tests - run: | - go test -race -covermode atomic -coverprofile=covprofile ./... - - name: Install goveralls - run: go install github.com/mattn/goveralls@latest - - - name: Send coverage - env: - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: goveralls -coverprofile=covprofile -service=github \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index cc923fb..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Test - run: go test -v ./... - - - name: Test - run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic - - - name: Coverage - run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 688142c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: go - -go: - - master - -script: - - go test -v ./... \ No newline at end of file diff --git a/README.md b/README.md index 97c8f75..740c961 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,24 @@ Golang Time -📦 Golang 时间组件 +📦 Golang Time [comment]: <> (go) -[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gotime?status.svg)](https://pkg.go.dev/go.dtapp.net/gotime) -[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gotime/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gotime) -[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gotime)](https://goreportcard.com/report/go.dtapp.net/gotime) -[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/gotime) +[![godoc](https://pkg.go.dev/badge/github.com/dtapps/gotime?status.svg)](https://pkg.go.dev/github.com/dtapps/gotime) +[![goproxy.cn](https://goproxy.cn/stats/github.com/dtapps/gotime/badges/download-count.svg)](https://goproxy.cn/stats/github.com/dtapps/gotime) +[![goreportcard.com](https://goreportcard.com/badge/github.com/dtapps/gotime)](https://goreportcard.com/report/github.com/dtapps/gotime) +[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/github.com/dtapps/gotime) #### 安装使用 ```go -go get -v -u go.dtapp.net/gotime +go get -v -u github.com/dtapps/gotime ``` #### 导入 ```go import ( - "go.dtapp.net/gotime" + "github.com/dtapps/gotime" ) ``` \ No newline at end of file diff --git a/go.mod b/go.mod index f7f33fd..54fc872 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module go.dtapp.net/gotime +module github.com/dtapps/gotime go 1.18 diff --git a/gotime.go b/gotime.go index 4905ba2..3bd7dfe 100644 --- a/gotime.go +++ b/gotime.go @@ -5,8 +5,6 @@ import ( "time" ) -const Version = "1.0.2" - // 时间格式化常量 const ( RFC3339Format = time.RFC3339 diff --git a/app_test.go b/gotime_test.go similarity index 57% rename from app_test.go rename to gotime_test.go index 8d6b278..a77d361 100644 --- a/app_test.go +++ b/gotime_test.go @@ -6,6 +6,7 @@ import ( func TestTime(t *testing.T) { t.Log("今天此刻:", Current().Now()) + t.Log("测试", Current().SetFormat("20060102150405")) t.Log("今天此刻格式化:", Current().Format()) t.Log("今天此刻日期:", Current().ToDateFormat()) t.Log("今天此刻时间:", Current().ToTimeFormat()) @@ -46,39 +47,34 @@ func TestTime(t *testing.T) { t.Log("本月开始时间:", Current().StartOfMonth().Format()) t.Log("本月结束时间:", Current().EndOfMonth().Format()) - t.Log("7100秒前的时间:", Current().BeforeSeconds(7100).Format()) - t.Log("2小时前的时间:", Current().BeforeHour(2).Format()) - t.Log("7100秒后的时间:", Current().AfterSeconds(7100).Format()) - t.Log("2小时后的时间:", Current().AfterHour(2).Format()) - - t.Log("相差多少小时(绝对值):", SetCurrentParse("2022-03-01T10:03:39+08:00").Format()) - t.Log("相差多少小时(绝对值):", SetCurrentParse("2022-03-04T11:12:47+08:00").Format()) - - t.Log("BSON:", Current().Bson()) + //t.Log("7100秒前的时间:", Current().BeforeSeconds(7100).Format()) + //t.Log("2小时前的时间:", Current().BeforeHour(2).Format()) + //t.Log("7100秒后的时间:", Current().AfterSeconds(7100).Format()) + //t.Log("2小时后的时间:", Current().AfterHour(2).Format()) } -func TestDayStartOfEnd(t *testing.T) { - t.Log("当前时间:", Current().Format()) - t.Log("今天开始时间:", Current().StartOfDay().Format()) - t.Log("今天结束时间:", Current().EndOfDay().Format()) - t.Log("当前时间戳:", Current().Timestamp()) - t.Log("今天开始时间戳:", Current().StartOfDay().Timestamp()) - t.Log("今天结束时间戳:", Current().EndOfDay().Timestamp()) - t.Log("n天前时间:", Current().BeforeDay(1).Format()) - t.Log("n天前开始时间戳:", Current().BeforeDay(1).StartOfDay().Format()) - t.Log("n天前结束时间戳:", Current().BeforeDay(1).EndOfDay().Format()) - t.Log("n天后时间:", Current().AfterDay(1).Format()) - t.Log("n天后开始时间戳:", Current().AfterDay(1).StartOfDay().Format()) - t.Log("n天后结束时间戳:", Current().AfterDay(1).EndOfDay().Format()) +func TestStartOfDay(t *testing.T) { + t.Log(Current().Format()) + t.Log(Current().StartOfDay().Format()) + t.Log(Current().EndOfDay().Format()) + t.Log(Current().Timestamp()) + t.Log(Current().StartOfDay().Timestamp()) + t.Log(Current().EndOfDay().Timestamp()) + t.Log(Current().BeforeDay(1).Format()) + t.Log(Current().BeforeDay(1).StartOfDay().Format()) + t.Log(Current().BeforeDay(1).EndOfDay().Format()) + t.Log(Current().AfterDay(1).Format()) + t.Log(Current().AfterDay(1).StartOfDay().Format()) + t.Log(Current().AfterDay(1).EndOfDay().Format()) } func TestDiff(t *testing.T) { - t.Log("相差多少分秒:", Current().DiffInSecond(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("相差多少分秒(绝对值):", Current().DiffInSecondWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("相差多少分钟:", Current().DiffInMinutes(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("相差多少分钟(绝对值):", Current().DiffInMinutesWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("相差多少小时:", Current().DiffInHour(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("相差多少小时(绝对值):", Current().DiffInHourWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time)) + t.Log(Current().DiffInHourWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time)) + t.Log(Current().DiffInHour(SetCurrentParse("2021-11-26 14:50:00").Time)) + t.Log(Current().DiffInMinutesWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time)) + t.Log(Current().DiffInMinutes(SetCurrentParse("2021-11-26 14:50:00").Time)) + t.Log(SetCurrentParse("2022-03-01T10:03:39+08:00").Format()) + t.Log(SetCurrentParse("2022-03-04T11:12:47+08:00").Format()) } func TestUnix(t *testing.T) { @@ -94,6 +90,11 @@ func Test2(t *testing.T) { t.Log(Current().Format()) } +func TestGt(t *testing.T) { + t.Log(SetCurrentParse("2022-04-06 15:05:24").Time) + t.Log(Current().Lte(SetCurrentParse("2022-07-18 17:05:24").Time)) +} + func TestTaoBao(t *testing.T) { i := 1 for { @@ -127,12 +128,3 @@ func TestMT(t *testing.T) { t.Log(Current().BeforeHour(24 * (day - 1)).Format()) } - -func TestCompare(t *testing.T) { - t.Log("是否大于:", Current().Gt(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("是否小于:", Current().Lt(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("是否等于:", Current().Eq(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("是否不等于:", Current().Ne(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("是否大于等于:", Current().Gte(SetCurrentParse("2021-11-26 14:50:00").Time)) - t.Log("是否小于等于:", Current().Lte(SetCurrentParse("2021-11-26 14:50:00").Time)) -} diff --git a/version.go b/version.go new file mode 100644 index 0000000..6363da3 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package gotime + +const Version = "1.0.3"