Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
dtapps | d2fc1af3be | 2 months ago |
dtapps | 1b8a3a8b18 | 2 months ago |
dtapps | e25da0cbd4 | 3 months ago |
dtapps | aae4112b32 | 4 months ago |
dtapps | ca62634337 | 6 months ago |
李光春 | d269b45582 | 2 years ago |
李光春 | 9f8bce0361 | 2 years ago |
李光春 | f7b17917ad | 2 years ago |
李光春 | ea8772e0c7 | 2 years ago |
李光春 | 953848c8c8 | 2 years ago |
李光春 | a157c5dfce | 2 years ago |
@ -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
|
|
@ -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
|
|
@ -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)
|
|
@ -1,7 +0,0 @@
|
|||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- master
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go test -v ./...
|
|
@ -1,25 +1,33 @@
|
|||||||
<h1>
|
<h1>
|
||||||
<a href="https://www.dtapp.net/">Golang Time</a>
|
<a href="https://www.dtapp.net/">Golang</a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
📦 Golang 时间组件
|
📦 Golang 时间
|
||||||
|
|
||||||
[comment]: <> (go)
|
[comment]: <> (go)
|
||||||
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gotime?status.svg)](https://pkg.go.dev/go.dtapp.net/gotime)
|
[![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)
|
[![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)
|
[![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)
|
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net%2Fgotime)
|
||||||
|
|
||||||
#### 安装使用
|
#### 安装
|
||||||
|
|
||||||
```go
|
```shell
|
||||||
go get -v -u go.dtapp.net/gotime
|
go get -v -u go.dtapp.net/gotime@v1.0.10
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 导入
|
#### 使用
|
||||||
|
|
||||||
|
```text
|
||||||
|
package main
|
||||||
|
|
||||||
```go
|
|
||||||
import (
|
import (
|
||||||
"go.dtapp.net/gotime"
|
"go.dtapp.net/gotime"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestVerification 验证字符串是否为时间
|
||||||
|
func TestVerification(t *testing.T) {
|
||||||
|
t.Log(gotime.Verification("2022-02-05 00:00:00", gotime.DateTimeFormat))
|
||||||
|
}
|
||||||
```
|
```
|
@ -0,0 +1,21 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
const (
|
||||||
|
DateTimeFormat = "2006-01-02 15:04:05"
|
||||||
|
DateTimeSFormat = "2006-01-0215:04:05"
|
||||||
|
DateTimeShrinkFormat = "2006-01-02 15:04"
|
||||||
|
DateTimeShrinkSFormat = "2006-01-0215:04"
|
||||||
|
DateFormat = "2006-01-02"
|
||||||
|
TimeFormat = "15:04:05"
|
||||||
|
TimeShrinkFormat = "15:04"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DateTimeZhFormat = "2006年01月02日 15点04分05秒"
|
||||||
|
DateTimeZhSFormat = "2006年01月02日15点04分05秒"
|
||||||
|
DateTimeZhShrinkFormat = "2006年01月02日 15点04分"
|
||||||
|
DateTimeZhShrinkSFormat = "2006年01月02日15点04分"
|
||||||
|
DateZhFormat = "2006年01月02日"
|
||||||
|
TimeZhFormat = "15点04分05秒"
|
||||||
|
TimeZhShrinkFormat = "15点04分"
|
||||||
|
)
|
@ -0,0 +1,23 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFormat(t *testing.T) {
|
||||||
|
t.Log("DateTimeFormat", Current().SetFormat(DateTimeFormat))
|
||||||
|
t.Log("DateTimeSFormat", Current().SetFormat(DateTimeSFormat))
|
||||||
|
t.Log("DateTimeShrinkFormat", Current().SetFormat(DateTimeShrinkFormat))
|
||||||
|
t.Log("DateTimeShrinkSFormat", Current().SetFormat(DateTimeShrinkSFormat))
|
||||||
|
t.Log("DateFormat", Current().SetFormat(DateFormat))
|
||||||
|
t.Log("TimeFormat", Current().SetFormat(TimeFormat))
|
||||||
|
t.Log("TimeShrinkFormat", Current().SetFormat(TimeShrinkFormat))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestZhFormat(t *testing.T) {
|
||||||
|
t.Log("DateTimeZhFormat", Current().SetFormat(DateTimeZhFormat))
|
||||||
|
t.Log("DateTimeZhSFormat", Current().SetFormat(DateTimeZhSFormat))
|
||||||
|
t.Log("DateTimeZhShrinkFormat", Current().SetFormat(DateTimeZhShrinkFormat))
|
||||||
|
t.Log("DateTimeZhShrinkSFormat", Current().SetFormat(DateTimeZhShrinkSFormat))
|
||||||
|
t.Log("DateZhFormat", Current().SetFormat(DateZhFormat))
|
||||||
|
t.Log("TimeZhFormat", Current().SetFormat(TimeZhFormat))
|
||||||
|
t.Log("TimeZhShrinkFormat", Current().SetFormat(TimeZhShrinkFormat))
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
module go.dtapp.net/gotime
|
module go.dtapp.net/gotime
|
||||||
|
|
||||||
go 1.18
|
go 1.22
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// Verification 验证字符串是否为时间
|
||||||
|
func Verification(str, layout string) (resp time.Time, err error) {
|
||||||
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
|
location, err := time.ParseInLocation(layout, str, loc)
|
||||||
|
if err != nil {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
|
return location, nil
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestVerification(t *testing.T) {
|
||||||
|
t.Log(Verification("2022-02-05 00:00:00", DateTimeFormat))
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
const Version = "1.0.10"
|
@ -0,0 +1,13 @@
|
|||||||
|
package gotime
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestVersion(t *testing.T) {
|
||||||
|
t.Log(Version)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkVersion(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.Log(Version)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue