Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 3f7de3f

Browse files
committed
Fixed WASM support
1 parent 85e4071 commit 3f7de3f

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

Sources/SwiftFoundation/Date.swift

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,49 +34,18 @@ public struct Date: Equatable, Hashable {
3434
public var timeIntervalSinceReferenceDate: TimeInterval
3535

3636
/// The time interval between the current date and 1 January 1970, GMT.
37-
public var timeIntervalsince1970: TimeInterval {
37+
public var timeIntervalSince1970: TimeInterval {
3838
get { return timeIntervalSinceReferenceDate + Date.timeIntervalBetween1970AndReferenceDate }
3939
set { timeIntervalSinceReferenceDate = newValue - Date.timeIntervalBetween1970AndReferenceDate }
4040
}
4141

42-
/**
43-
The time interval between the date and the current date and time.
44-
45-
If the date is earlier than the current date and time, the this property’s value is negative.
46-
47-
- SeeAlso: `timeIntervalSince(_:)`
48-
- SeeAlso: `timeIntervalSince1970`
49-
- SeeAlso: `timeIntervalSinceReferenceDate`
50-
*/
51-
public var timeIntervalSinceNow: TimeInterval {
52-
return timeIntervalSinceReferenceDate - Date.timeIntervalSinceReferenceDate
53-
}
54-
55-
/**
56-
The interval between the date object and 00:00:00 UTC on 1 January 1970.
57-
58-
This property’s value is negative if the date object is earlier than 00:00:00 UTC on 1 January 1970.
59-
60-
- SeeAlso: `timeIntervalSince(_:)`
61-
- SeeAlso: `timeIntervalSinceNow`
62-
- SeeAlso: `timeIntervalSinceReferenceDate`
63-
*/
64-
public var timeIntervalSince1970: TimeInterval {
65-
return timeIntervalSinceReferenceDate + Date.timeIntervalBetween1970AndReferenceDate
66-
}
67-
6842
// MARK: - Initialization
6943

7044
/// Returns an `Date` initialized relative to 00:00:00 UTC on 1 January 2001 by a given number of seconds.
7145
public init(timeIntervalSinceReferenceDate timeInterval: TimeInterval) {
7246
self.timeIntervalSinceReferenceDate = timeInterval
7347
}
7448

75-
/// Returns a `Date` initialized relative to the current date and time by a given number of seconds.
76-
public init(timeIntervalSinceNow: TimeInterval) {
77-
self.timeIntervalSinceReferenceDate = timeIntervalSinceNow + Date.timeIntervalSinceReferenceDate
78-
}
79-
8049
/// Returns a `Date` initialized relative to 00:00:00 UTC on 1 January 1970 by a given number of seconds.
8150
public init(timeIntervalSince1970: TimeInterval) {
8251
self.timeIntervalSinceReferenceDate = timeIntervalSince1970 - Date.timeIntervalBetween1970AndReferenceDate
@@ -126,12 +95,13 @@ public struct Date: Equatable, Hashable {
12695
}
12796
}
12897

98+
#if !arch(wasm32)
99+
129100
// MARK: - CustomStringConvertible
130101

131102
extension SwiftFoundation.Date: CustomStringConvertible {
132103

133104
public var description: String {
134-
// TODO: Custom date printing
135105
return timeIntervalSinceReferenceDate.description
136106
}
137107
}
@@ -145,6 +115,8 @@ extension SwiftFoundation.Date: CustomDebugStringConvertible {
145115
}
146116
}
147117

118+
#endif
119+
148120
// MARK: - Comparable
149121

150122
extension SwiftFoundation.Date: Comparable {

Sources/SwiftFoundation/POSIXTime.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import Darwin.C
1212
import Glibc
1313
#endif
1414

15+
#if !arch(wasm32)
16+
1517
// MARK: - Date
1618

1719
public extension Date {
@@ -26,6 +28,24 @@ public extension Date {
2628
init() {
2729
self.timeIntervalSinceReferenceDate = Date.timeIntervalSinceReferenceDate
2830
}
31+
32+
/// Returns a `Date` initialized relative to the current date and time by a given number of seconds.
33+
init(timeIntervalSinceNow: TimeInterval) {
34+
self.timeIntervalSinceReferenceDate = timeIntervalSinceNow + Date.timeIntervalSinceReferenceDate
35+
}
36+
37+
/**
38+
The time interval between the date and the current date and time.
39+
40+
If the date is earlier than the current date and time, the this property’s value is negative.
41+
42+
- SeeAlso: `timeIntervalSince(_:)`
43+
- SeeAlso: `timeIntervalSince1970`
44+
- SeeAlso: `timeIntervalSinceReferenceDate`
45+
*/
46+
var timeIntervalSinceNow: TimeInterval {
47+
return timeIntervalSinceReferenceDate - Date.timeIntervalSinceReferenceDate
48+
}
2949
}
3050

3151
// MARK: - POSIX Time
@@ -35,10 +55,8 @@ internal extension timeval {
3555
static func timeOfDay() throws -> timeval {
3656

3757
var timeStamp = timeval()
38-
3958
guard gettimeofday(&timeStamp, nil) == 0
4059
else { throw POSIXError.fromErrno() }
41-
4260
return timeStamp
4361
}
4462

@@ -105,6 +123,8 @@ internal extension tm {
105123
}
106124
}
107125

126+
#endif
127+
108128
// MARK: - Cross-Platform Support
109129

110130
#if canImport(Darwin)
@@ -125,5 +145,5 @@ internal func modf(value: Double) -> (Double, Double) {
125145

126146
return (decimalValue, integerValue)
127147
}
128-
148+
129149
#endif

0 commit comments

Comments
 (0)