宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
//  SwiftDate
//  Parse, validate, manipulate, and display dates, time and timezones in Swift
//
//  Created by Daniele Margutti
//   - Web: https://www.danielemargutti.com
//   - Twitter: https://twitter.com/danielemargutti
//   - Mail: hello@danielemargutti.com
//
//  Copyright © 2019 Daniele Margutti. Licensed under MIT License.
//
 
import Foundation
 
public extension Date {
 
    /// Indicates whether the month is a leap month.
    var isLeapMonth: Bool {
        return inDefaultRegion().isLeapMonth
    }
 
    /// Indicates whether the year is a leap year.
    var isLeapYear: Bool {
        return inDefaultRegion().isLeapYear
    }
 
    /// Julian day is the continuous count of days since the beginning of
    /// the Julian Period used primarily by astronomers.
    var julianDay: Double {
        return inDefaultRegion().julianDay
    }
 
    /// The Modified Julian Date (MJD) was introduced by the Smithsonian Astrophysical Observatory
    /// in 1957 to record the orbit of Sputnik via an IBM 704 (36-bit machine)
    /// and using only 18 bits until August 7, 2576.
    var modifiedJulianDay: Double {
        return inDefaultRegion().modifiedJulianDay
    }
 
    /// Return elapsed time expressed in given components since the current receiver and a reference date.
    ///
    /// - Parameters:
    ///   - refDate: reference date (`nil` to use current date in the same region of the receiver)
    ///   - component: time unit to extract.
    /// - Returns: value
    func getInterval(toDate: Date?, component: Calendar.Component) -> Int64 {
        return inDefaultRegion().getInterval(toDate: toDate?.inDefaultRegion(), component: component)
    }
}