一系列bug

This commit is contained in:
DDIsFriend
2023-09-12 18:58:43 +08:00
parent 66a3708532
commit 220155ce89
63 changed files with 13460 additions and 10213 deletions

View 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
View 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
View File

@@ -0,0 +1,29 @@
# DDDateKit_Private
[![CI Status](https://img.shields.io/travis/DDIsFriend/DDDateKit_Private.svg?style=flat)](https://travis-ci.org/DDIsFriend/DDDateKit_Private)
[![Version](https://img.shields.io/cocoapods/v/DDDateKit_Private.svg?style=flat)](https://cocoapods.org/pods/DDDateKit_Private)
[![License](https://img.shields.io/cocoapods/l/DDDateKit_Private.svg?style=flat)](https://cocoapods.org/pods/DDDateKit_Private)
[![Platform](https://img.shields.io/cocoapods/p/DDDateKit_Private.svg?style=flat)](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.