Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
zhangyongji
/
MRFramework
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fe5601da
authored
Sep 10, 2019
by
Sarkizz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
公开方法
parent
374db0dc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
MRFramework/MRFramework/Extensions/Foundation/Date+util.swift
+21
-21
No files found.
MRFramework/MRFramework/Extensions/Foundation/Date+util.swift
View file @
fe5601da
...
...
@@ -8,7 +8,7 @@
import
Foundation
enum
TIConvertDateType
{
public
enum
TIConvertDateType
{
case
now
case
s1970
case
reference
...
...
@@ -16,7 +16,7 @@ enum TIConvertDateType {
}
extension
Date
{
static
func
defaultFormatter
()
->
DateFormatter
{
public
static
func
defaultFormatter
()
->
DateFormatter
{
let
formatter
=
DateFormatter
()
formatter
.
locale
=
.
current
formatter
.
timeZone
=
.
current
...
...
@@ -24,7 +24,7 @@ extension Date {
return
formatter
}
func
string
(
_
format
:
String
=
"yyyy.MM.dd hh:mm:ss"
,
local
:
Locale
=
.
current
,
timeZone
:
TimeZone
=
.
current
)
->
String
{
public
func
string
(
_
format
:
String
=
"yyyy.MM.dd hh:mm:ss"
,
local
:
Locale
=
.
current
,
timeZone
:
TimeZone
=
.
current
)
->
String
{
let
formatter
=
DateFormatter
()
formatter
.
locale
=
local
formatter
.
dateFormat
=
format
...
...
@@ -32,11 +32,11 @@ extension Date {
return
formatter
.
string
(
from
:
self
)
}
func
countdown
(
to
date
:
Date
,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
public
func
countdown
(
to
date
:
Date
,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
return
Countdown
(
with
:
self
,
endTime
:
date
)
.
inSecond
()
.
handler
(
handler
)
}
func
countdown
(
from
date
:
Date
,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
public
func
countdown
(
from
date
:
Date
,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
return
Countdown
(
with
:
date
,
endTime
:
self
)
.
inSecond
()
.
handler
(
handler
)
}
}
...
...
@@ -105,7 +105,7 @@ extension Date {
}
extension
TimeInterval
{
func
date
(
_
type
:
TIConvertDateType
=
.
reference
)
->
Date
{
public
func
date
(
_
type
:
TIConvertDateType
=
.
reference
)
->
Date
{
switch
type
{
case
.
now
:
return
Date
(
timeIntervalSinceNow
:
self
)
...
...
@@ -118,16 +118,16 @@ extension TimeInterval {
}
}
func
countdown
(
_
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
public
func
countdown
(
_
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
return
Countdown
(
with
:
self
)
.
inSecond
()
.
handler
(
handler
)
}
func
`
repeat
`
(
_
handler
:
@escaping
CountdownRepeatingBlock
)
->
Countdown
{
public
func
`
repeat
`
(
_
handler
:
@escaping
CountdownRepeatingBlock
)
->
Countdown
{
return
Countdown
(
repeatInSec
:
self
)
.
repeat
(
handler
)
}
}
enum
CountdownSec
{
public
enum
CountdownSec
{
case
up
(
_
sec
:
Int
,
_
stop
:
CountdownSecUpStopBlock
?)
case
down
(
_
sec
:
Int
)
...
...
@@ -150,13 +150,13 @@ enum CountdownSec {
}
}
typealias
CountdownHandler
=
(
_
day
:
Int
,
_
hour
:
Int
,
_
minute
:
Int
,
_
second
:
Int
)
->
Void
typealias
CountdownSecUpStopBlock
=
(
_
timeInterval
:
TimeInterval
)
->
Bool
typealias
CountdownRepeatingBlock
=
(
_
cd
:
Countdown
?)
->
Void
public
typealias
CountdownHandler
=
(
_
day
:
Int
,
_
hour
:
Int
,
_
minute
:
Int
,
_
second
:
Int
)
->
Void
public
typealias
CountdownSecUpStopBlock
=
(
_
timeInterval
:
TimeInterval
)
->
Bool
public
typealias
CountdownRepeatingBlock
=
(
_
cd
:
Countdown
?)
->
Void
final
class
Countdown
{
public
final
class
Countdown
{
p
rivate
static
let
defaultRepeating
:
TimeInterval
=
1
p
ublic
static
let
defaultRepeating
:
TimeInterval
=
1
private
var
startTime
:
Date
?
private
var
endTime
:
Date
?
...
...
@@ -175,24 +175,24 @@ final class Countdown {
}
convenience
init
(
with
startTime
:
Date
,
endTime
:
Date
)
{
public
convenience
init
(
with
startTime
:
Date
,
endTime
:
Date
)
{
self
.
init
()
self
.
startTime
=
startTime
self
.
endTime
=
endTime
}
convenience
init
(
with
startTime
:
String
,
endTime
:
String
,
formatter
:
DateFormatter
=
Date
.
defaultFormatter
())
{
public
convenience
init
(
with
startTime
:
String
,
endTime
:
String
,
formatter
:
DateFormatter
=
Date
.
defaultFormatter
())
{
self
.
init
()
self
.
startTime
=
formatter
.
date
(
from
:
startTime
)
self
.
endTime
=
formatter
.
date
(
from
:
endTime
)
}
convenience
init
(
with
timeInterval
:
TimeInterval
)
{
public
convenience
init
(
with
timeInterval
:
TimeInterval
)
{
self
.
init
()
self
.
countdownInterval
=
timeInterval
}
convenience
init
(
repeatInSec
:
TimeInterval
)
{
public
convenience
init
(
repeatInSec
:
TimeInterval
)
{
self
.
init
()
self
.
repeatInSec
=
repeatInSec
}
...
...
@@ -231,11 +231,11 @@ extension Countdown {
return
self
}
func
resume
()
{
public
func
resume
()
{
timer
.
resume
()
}
func
resetTimer
()
{
public
func
resetTimer
()
{
timer
.
cancel
()
timer
=
nil
}
...
...
@@ -325,7 +325,7 @@ extension Countdown {
}
extension
Int
{
func
countup
(
stop
:
CountdownSecUpStopBlock
?,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
public
func
countup
(
stop
:
CountdownSecUpStopBlock
?,
handler
:
@escaping
CountdownHandler
)
->
Countdown
{
return
Countdown
()
.
limitCound
(
self
)
.
inSecond
(
.
up
(
1
,
stop
))
.
handler
(
handler
)
}
}
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