Skip to content

Commit

Permalink
Merge pull request #2884 from compnerd/populate-creationDate
Browse files Browse the repository at this point in the history
Foundation: populate the `.creationDate` attribute on Windows
  • Loading branch information
millenomi committed Sep 28, 2020
2 parents 82b8fa2 + 3eda66b commit fd7c1e9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/Foundation/FileManager.swift
Expand Up @@ -544,6 +544,14 @@ open class FileManager : NSObject {
result[.creationDate] = creationDate
#else
let s = try _lstatFile(atPath: path)
// Darwin provides a `st_ctimespec` rather than the traditional Unix
// `st_ctime` field. Since `st_ctime` is more traditional, special case
// Darwin platforms and convert the timespec to the absolute time.
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
result[.creationDate] = Date(timespec: s.st_ctimespec)
#else
result[.creationDate] = Date(timeIntervalSince1970: TimeInterval(s.st_ctime))
#endif
#endif

result[.size] = NSNumber(value: UInt64(s.st_size))
Expand Down

0 comments on commit fd7c1e9

Please sign in to comment.