Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
6ad607ab
Commit
6ad607ab
authored
Nov 15, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
float精度计算
parent
0eaf471d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
ArrayUtil_test.go
util/ArrayUtil_test.go
+4
-4
DateUtil.go
util/DateUtil.go
+12
-3
No files found.
util/ArrayUtil_test.go
View file @
6ad607ab
...
...
@@ -10,10 +10,10 @@ import (
func
TestArrayContainsInterface
(
t
*
testing
.
T
)
{
var
areaIds
[]
time
.
Time
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-02-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-03-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
PareDateTime
(
"2022-12-09 22:09:12"
))
fmt
.
Println
(
ArrayContains
[
time
.
Time
](
areaIds
,
PareDateTime
(
"2022-02-10 22:09:12"
)))
areaIds
=
append
(
areaIds
,
Par
s
eDateTime
(
"2022-02-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
Par
s
eDateTime
(
"2022-03-09 22:09:12"
))
areaIds
=
append
(
areaIds
,
Par
s
eDateTime
(
"2022-12-09 22:09:12"
))
fmt
.
Println
(
ArrayContains
[
time
.
Time
](
areaIds
,
Par
s
eDateTime
(
"2022-02-10 22:09:12"
)))
}
func
TestDifference
(
t
*
testing
.
T
)
{
...
...
util/DateUtil.go
View file @
6ad607ab
...
...
@@ -27,12 +27,12 @@ func FormatDateMillTime(dateTime time.Time) string {
return
dateTime
.
Format
(
formatSimple0
)
}
func
PareDateStart
(
date
string
)
time
.
Time
{
func
Par
s
eDateStart
(
date
string
)
time
.
Time
{
stamp
,
_
:=
time
.
ParseInLocation
(
formatSimple1
,
date
+
" 00:00:00"
,
time
.
Local
)
return
stamp
}
func
PareDateTime
(
dateTime
string
)
time
.
Time
{
func
Par
s
eDateTime
(
dateTime
string
)
time
.
Time
{
stamp
,
_
:=
time
.
ParseInLocation
(
formatSimple1
,
dateTime
,
time
.
Local
)
return
stamp
}
...
...
@@ -66,7 +66,7 @@ func TimeSubDays(t1, t2 time.Time) int {
}
}
// TimeSubMinute t1比t2多多少分钟
// TimeSubMinute t1比t2多多少分钟
,向上取整
func
TimeSubMinute
(
t1
,
t2
*
time
.
Time
)
int
{
if
t1
.
Location
()
.
String
()
!=
t2
.
Location
()
.
String
()
{
return
-
1
...
...
@@ -75,6 +75,15 @@ func TimeSubMinute(t1, t2 *time.Time) int {
return
int
(
math
.
Ceil
(
seconds
/
60
))
//向上取整
}
// TimeSubMinuteFloor t1比t2多多少分钟,向上取整
func
TimeSubMinuteFloor
(
t1
,
t2
*
time
.
Time
)
int
{
if
t1
.
Location
()
.
String
()
!=
t2
.
Location
()
.
String
()
{
return
-
1
}
seconds
:=
t1
.
Sub
(
*
t2
)
.
Seconds
()
return
int
(
math
.
Floor
(
seconds
/
60
))
//向上取整
}
func
MilSecond
(
time
time
.
Time
)
int64
{
return
time
.
UnixNano
()
/
1e6
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment