一系列bug
This commit is contained in:
207
Pods/DDDateKit_Private/DDDateKit_Private/Classes/DDDate.swift
generated
Normal file
207
Pods/DDDateKit_Private/DDDateKit_Private/Classes/DDDate.swift
generated
Normal file
@@ -0,0 +1,207 @@
|
||||
//
|
||||
// DDDate.swift
|
||||
// DDDateKit_Private
|
||||
// Created by DDIsFriend on 2023/9/8.
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
public let DDDATE = DDDate.default
|
||||
|
||||
open class DDDate {
|
||||
public static let `default` = DDDate()
|
||||
// 设置一个全局使用的
|
||||
public var globalLocale : String = "zh_CN"
|
||||
public var globalTimeZoneIdentifier : String = "UTC+8"
|
||||
|
||||
func getLocale(locale:String?) -> String {
|
||||
var _locale = globalLocale
|
||||
if let locale {
|
||||
_locale = locale
|
||||
}
|
||||
return _locale
|
||||
}
|
||||
|
||||
func getTimeZoneIdentifier(timeZoneIdentifier:String?) -> String {
|
||||
var _timeZoneIdentifier = globalTimeZoneIdentifier
|
||||
if let timeZoneIdentifier {
|
||||
_timeZoneIdentifier = timeZoneIdentifier
|
||||
}
|
||||
return _timeZoneIdentifier
|
||||
}
|
||||
|
||||
func getDateFormatter(format:String,locale:String? = nil,timeZoneIdentifier:String? = nil) -> DateFormatter {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = format
|
||||
dateFormatter.calendar = Calendar(identifier: .gregorian)
|
||||
dateFormatter.locale = Locale(identifier: getLocale(locale: locale))
|
||||
dateFormatter.timeZone = TimeZone.init(identifier: getTimeZoneIdentifier(timeZoneIdentifier: timeZoneIdentifier))
|
||||
return dateFormatter
|
||||
}
|
||||
}
|
||||
|
||||
extension Date {
|
||||
|
||||
/// 返回一个毫秒的时间戳
|
||||
/// - Returns: 时间戳
|
||||
public func dd_timeintervalSssSince1970() -> TimeInterval {
|
||||
let timeInterval = timeIntervalSince1970
|
||||
return timeInterval * 1000
|
||||
}
|
||||
|
||||
/// 将日期转成字符串
|
||||
/// - Parameters:
|
||||
/// - format: 指定字符串格式
|
||||
/// - locale: 本地化
|
||||
/// - timeZoneIdentifier: 时区
|
||||
/// - Returns: 时间的字符串格式
|
||||
public func dd_toString(format:String,locale:String? = nil,timeZoneIdentifier:String? = nil) -> String {
|
||||
return DDDATE.getDateFormatter(format: format,locale: locale,timeZoneIdentifier: timeZoneIdentifier).string(from: self)
|
||||
}
|
||||
|
||||
/// 判断date是不是昨天
|
||||
/// - Returns: 是不是
|
||||
public func isYesterday() -> Bool {
|
||||
return Calendar.current.isDateInYesterday(self)
|
||||
}
|
||||
|
||||
/// 判断date是不是今天
|
||||
/// - Returns: 是不是
|
||||
public func isToday() -> Bool {
|
||||
return Calendar.current.isDateInToday(self)
|
||||
}
|
||||
|
||||
/// 判断date是不是明天
|
||||
/// - Returns: 是不是
|
||||
public func isTomorrow() -> Bool {
|
||||
return Calendar.current.isDateInTomorrow(self)
|
||||
}
|
||||
|
||||
/// 指定一种固定模式,例如消息通知里时间的刚刚,今天,昨天以及指定日期模式
|
||||
/// - Returns: 返回字符串格式,
|
||||
public func dd_pushNotificationDateFormatString() -> String {
|
||||
let currentDate = Date()
|
||||
let duration = currentDate.timeIntervalSince1970 - timeIntervalSince1970
|
||||
if duration < 0 {
|
||||
return "时间穿越了"
|
||||
}
|
||||
|
||||
if isToday() == true {
|
||||
let min = Int(floor(duration / 60))
|
||||
let hour = Int(floor(duration / 3600))
|
||||
|
||||
if duration < 60 {
|
||||
return "刚刚"
|
||||
}
|
||||
|
||||
// 当小时存在且是今天
|
||||
if hour > 0 {
|
||||
return "\(hour)小时前"
|
||||
}
|
||||
// 来到这里说明小时不存在
|
||||
if min > 0 {
|
||||
return "\(min)分钟前"
|
||||
}
|
||||
|
||||
return "今天\(dd_toString(format: "HH:mm:ss"))"
|
||||
}
|
||||
|
||||
if isYesterday() == true {
|
||||
return "昨天\(dd_toString(format: "HH:mm:ss"))"
|
||||
}
|
||||
|
||||
return dd_toString(format: "yyyy-MM-dd HH:mm:ss")
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
/// 当前时间的字符串和另一个字符串时间进行大小的比较
|
||||
/// - Parameters:
|
||||
/// - dateString: 比较的时间
|
||||
/// - format: 比较时间的格式,时间比较需保持格式一致
|
||||
/// - Returns: 大于返回true
|
||||
public func dd_compare(dateString:String,format:String) -> ComparisonResult? {
|
||||
let date = dd_toDate(format: self)
|
||||
let compareDate = dd_toDate(format: self)
|
||||
guard date != nil,compareDate != nil else {
|
||||
return nil
|
||||
}
|
||||
return date!.compare(compareDate!)
|
||||
}
|
||||
|
||||
/// 将日期的字符串转成date
|
||||
/// - Parameters:
|
||||
/// - format: 当前字符串日期的格式
|
||||
/// - locale: 本地化区域
|
||||
/// - timeZoneIdentifier: 时区
|
||||
/// - Returns: date
|
||||
public func dd_toDate(format:String,locale:String? = nil,timeZoneIdentifier:String? = nil) -> Date? {
|
||||
return DDDATE.getDateFormatter(format: format,locale: locale,timeZoneIdentifier: timeZoneIdentifier).date(from: self)
|
||||
}
|
||||
|
||||
|
||||
/// 将字符串转换成时间戳秒
|
||||
/// - Parameter format: 字符串时间格式
|
||||
/// - Returns: 时间戳
|
||||
public func dd_timeIntervalSince1970(format:String) -> TimeInterval? {
|
||||
let date = dd_toDate(format: format)
|
||||
guard date != nil else {
|
||||
return nil
|
||||
}
|
||||
return date!.timeIntervalSince1970
|
||||
}
|
||||
|
||||
/// 将字符串转换成时间戳毫秒
|
||||
/// - Parameter format: 字符串时间格式
|
||||
/// - Returns: 时间戳
|
||||
public func dd_timeIntervalSssSince1970(format:String) -> TimeInterval? {
|
||||
let timeInterval = dd_timeIntervalSince1970(format: format)
|
||||
guard timeInterval != nil else {
|
||||
return nil
|
||||
}
|
||||
return timeInterval! * 1000
|
||||
}
|
||||
|
||||
|
||||
/// 当前时间是不是昨天
|
||||
/// - Parameter format: 时间格式
|
||||
/// - Returns: 是不是
|
||||
public func isYesterday(format:String) -> Bool {
|
||||
let date = dd_toDate(format: format)
|
||||
guard date != nil else {
|
||||
return false
|
||||
}
|
||||
return date!.isYesterday()
|
||||
}
|
||||
|
||||
/// 当前时间是不是今天
|
||||
/// - Parameter format: 时间格式
|
||||
/// - Returns: 是不是
|
||||
public func isToday(format:String) -> Bool {
|
||||
let date = dd_toDate(format: format)
|
||||
guard date != nil else {
|
||||
return false
|
||||
}
|
||||
return date!.isToday()
|
||||
}
|
||||
|
||||
/// 当前时间是不是明天
|
||||
/// - Parameter format: 时间格式
|
||||
/// - Returns: 是不是
|
||||
public func isTomorrow(format:String) -> Bool {
|
||||
let date = dd_toDate(format: format)
|
||||
guard date != nil else {
|
||||
return false
|
||||
}
|
||||
return date!.isTomorrow()
|
||||
}
|
||||
|
||||
/// 指定一种固定模式,例如消息通知里时间的刚刚,今天,昨天以及指定日期模式
|
||||
/// - Parameters:
|
||||
/// - format: 当前字符串时间的格式
|
||||
/// - Returns: 字符串
|
||||
public func dd_pushNotificationDateFormatString(format:String) -> String? {
|
||||
let date = dd_toDate(format: format)
|
||||
return date?.dd_pushNotificationDateFormatString()
|
||||
}
|
||||
}
|
||||
19
Pods/DDDateKit_Private/LICENSE
generated
Normal file
19
Pods/DDDateKit_Private/LICENSE
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2023 DDIsFriend <DDIsFriend@163.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
29
Pods/DDDateKit_Private/README.md
generated
Normal file
29
Pods/DDDateKit_Private/README.md
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
# DDDateKit_Private
|
||||
|
||||
[](https://travis-ci.org/DDIsFriend/DDDateKit_Private)
|
||||
[](https://cocoapods.org/pods/DDDateKit_Private)
|
||||
[](https://cocoapods.org/pods/DDDateKit_Private)
|
||||
[](https://cocoapods.org/pods/DDDateKit_Private)
|
||||
|
||||
## Example
|
||||
|
||||
To run the example project, clone the repo, and run `pod install` from the Example directory first.
|
||||
|
||||
## Requirements
|
||||
|
||||
## Installation
|
||||
|
||||
DDDateKit_Private is available through [CocoaPods](https://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'DDDateKit_Private'
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
DDIsFriend, DDIsFriend@163.com
|
||||
|
||||
## License
|
||||
|
||||
DDDateKit_Private is available under the MIT license. See the LICENSE file for more info.
|
||||
Reference in New Issue
Block a user