malcommac / SwiftDate

🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.
MIT License
7.64k stars 768 forks source link

'DateComponentsFormatter' is unavailable for Linux #714

Open edmw opened 4 years ago

edmw commented 4 years ago

Hi,

when compiling with Linux I get this error (using version 6.1 and Swift 5):

TimeInterval+Formatter.swift:34:38: error: 'DateComponentsFormatter' is unavailable: Not supported in swift-corelibs-foundation
                public var zeroFormattingBehavior: DateComponentsFormatter.ZeroFormattingBehavior?
                                                   ^~~~~~~~~~~~~~~~~~~~~~~
Foundation.DateComponentsFormatter:2:12: note: 'DateComponentsFormatter' has been explicitly marked unavailable here

Seems to me that DateComponentsFormatter is not available for Linux (unfortunately, I couldn't find out if it‘s just not there yet or never will be).

Any idea how I can get around this?

MickaelCruzDB commented 4 years ago

Same issue. How is possible to fix this ? thanks!

kaishin commented 4 years ago

@malcommac Please consider either fixing this or removing the claim that this library works for Linux.

keyvchan commented 4 years ago

Same here, please consider fixing this, thanks.

Maxim-Inv commented 4 years ago

Unfortunately DateComponentsFormatter isn't implemented yet https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md

Maxim-Inv commented 4 years ago

There is only one way to compile SwiftDate library on Linux - disable using of DateComponentsFormatter. I've made changes to compile my project on Linux. You can use it: .package(url: "https://github.com/Maxim-Inv/SwiftDate.git", .branch("master")),

amkomatz commented 4 years ago

Any update on this?

Kishimotovn commented 3 years ago

Please we need this!.

Maxim-Inv commented 3 years ago

@Kishimotovn you can use my fix: .package(url: "https://github.com/Maxim-Inv/SwiftDate.git", .branch("master")),

bordunosp commented 3 years ago

first "commented on 31 Dec 2019" really? not yet? ..probably never..

Maxim-Inv commented 3 years ago

@bordunosp You can use my fork, I have just update it .package(url: "https://github.com/Maxim-Inv/SwiftDate.git", .branch("master")),

bordunosp commented 3 years ago

@bordunosp You can use my fork, I have just update it .package(url: "https://github.com/Maxim-Inv/SwiftDate.git", .branch("master")),

My regards. Refused already from half of the external packages) I don't think swift is ready for Linux, although I want to use it now)) A very contradictory feeling

Maxim-Inv commented 3 years ago

You shouldn't think so. But you should be ready to make fixes if you really need some package in your project. Or wait when someone makes it. I started with Vapor 3, then moved to the beta version of Vapor 4, and only recently it became a full release version. I have five projects running on the Linux, so I can confidently say that Swift works well.

bordunosp commented 3 years ago

You shouldn't think so. But you should be ready to make fixes if you really need some package in your project. Or wait when someone makes it. I started with Vapor 3, then moved to the beta version of Vapor 4, and only recently it became a full release version. I have five projects running on the Linux, so I can confidently say that Swift works well.

what do you use to communicate with external API? Some kind of REST requests module? The default URLSession, like Alamofire, is very awkward to use. Maybe you can suggest something usable with habitual ".wait()"

Maxim-Inv commented 3 years ago

So I'm using Vapor for a server application, I use the inner Vapor class to get data from a remote server. Why do you think URLSession is very awkward? I guess that you did not deal with what was before in Objective C, that was really uncomfortable.

bordunosp commented 3 years ago

Vapor is not my way). Using clear grpc services

URLSession is uncomfortable because swift still have not paradigm "async/await" and I must use DispatchSemaphore vs DispatchGroup together. Although, perhaps my approach is fundamentally wrong. Perhaps you will look at the code and help a newbie with a specific example (although the question is already far from the original issue :))


        var error: Error?
        var newFilePathPart: String?

        let group = DispatchGroup(); group.enter(); DispatchQueue.global(qos: .userInteractive).async {
            let semaphore     = DispatchSemaphore(value: 0)
            let sessionConfig = URLSessionConfiguration.default
                sessionConfig.timeoutIntervalForRequest = (Date() + jobTimeout.seconds).timeIntervalSinceNow

            URLSession(configuration: sessionConfig).downloadTask(with: fileUrl) {(tmpFile, response, err) in
                do {
                    guard err == nil else {
                        throw err!
                    }
                    guard tmpFile != nil else {
                        throw ErrorsHelper.Server(msg: "Cant unwrap tmpFile")
                    }

                    let mime = try MimeTypeHelper.byFilePath(tmpFile!.path)

                    guard allowedExts.count == 0 || allowedExts.contains(mime.ext) else {
                        throw ErrorsHelper.Server(msg: "Current ext '\(mime.ext)' not allowed by allowedExts: \(allowedExts.joined(separator:","))")
                    }

                    var fileName = ""
                    let fileData = try Data(contentsOf: tmpFile!)
                    let datePath = "\(Date().year)-\(Date().month)"
                    let savePath = Path.cwd.join(ConfigHelper.shared.path.staticPath).join(saveTo).join(datePath)
                    if !savePath.isDirectory {
                        try savePath.mkdir(MakeDirectoryOptions.p)
                    }

                    repeat {
                        fileName = "".random(length: 32).lowercased() + ".\(mime.ext)"
                    } while savePath.join(fileName).isFile

                    try fileData.write(to: savePath.join(fileName))

                    newFilePathPart = "\(datePath)/\(fileName)"
                } catch let err {
                    error = err
                }
                semaphore.signal()
            }.resume()

            semaphore.wait()
            group.leave()
        }; group.wait(); guard error == nil else {
            throw ErrorsHelper.Server(msg: "Cant download file by url: \(url) -> \(error!)")
        }
bordunosp commented 3 years ago

I think this is what I was looking for: https://www.perfect.org/docs/cURL.html Looks pretty good (without DispatchGroup and Semaphore, and still can throw exception inside call method - perfect)

let url = "https://httpbin.org/get?p1=v1&p2=v2"
if let json = try CURLRequest(url).promise().then { return try $0().bodyJSON }.wait() {
    ...
}
patchthecode commented 2 years ago

@Maxim-Inv are you serious? your fork only disabled few lines of code (half of which are tests). Why doesnt the project owner not merge it?

Maxim-Inv commented 2 years ago

@patchthecode as you said I just commented a few lines of code only to avoid error on Linux. I think it only a workaround, not a fix.

albertodebortoli commented 8 months ago

Irrespective on this library, I'm having the same problem today on Linux.

Unbelievable that both RelativeDateTimeFormatter and DateComponentsFormatter are unavailable in the official Swift image (using 5.9.2).

Getting

error: cannot find 'RelativeDateTimeFormatter' in scope
error: 'DateComponentsFormatter' is unavailable: Not supported in swift-corelibs-foundation

Not sure what else to use.