mirror of
https://github.com/apple/swift-nio
synced 2026-11-22 04:30:41 +00:00
Split FoundationEssentials extensions from NIOFoundationCompat ### Motivation: Resolves #3038 ### Modifications: Split NIOFoundationCompat into two and only import FoundationEssentials and NIOFoundationEssentialsCompat where appropriate. ### Result: ByteBuffer/Codable extensions can be used without vendoring the code or linking to Foundation. Co-authored-by: Johannes Weiss <johannesweiss@apple.com> Co-authored-by: Fabian Fett <fabianfett@apple.com>
36 lines
999 B
Swift
36 lines
999 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import _NIOFileSystem
|
|
|
|
#if canImport(FoundationEssentials)
|
|
import struct FoundationEssentials.Date
|
|
#else
|
|
import struct Foundation.Date
|
|
#endif
|
|
|
|
extension Date {
|
|
public init(timespec: FileInfo.Timespec) {
|
|
let timeInterval = Double(timespec.seconds) + Double(timespec.nanoseconds) / 1_000_000_000
|
|
self = Date(timeIntervalSince1970: timeInterval)
|
|
}
|
|
}
|
|
|
|
extension FileInfo.Timespec {
|
|
/// The UTC time of the timestamp.
|
|
public var date: Date {
|
|
Date(timespec: self)
|
|
}
|
|
}
|