SwiftDate icon indicating copy to clipboard operation
SwiftDate copied to clipboard

'DateComponentsFormatter' is unavailable for Linux

Open edmw opened this issue 5 years ago β€’ 19 comments

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?

edmw avatar Dec 31 '19 10:12 edmw

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

MickaelCruzDB avatar Jan 12 '20 14:01 MickaelCruzDB

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

kaishin avatar Jan 12 '20 19:01 kaishin

Same here, please consider fixing this, thanks.

keyvchan avatar Mar 17 '20 09:03 keyvchan

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

Maxim-Inv avatar May 22 '20 12:05 Maxim-Inv

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")),

Maxim-Inv avatar May 22 '20 12:05 Maxim-Inv

Any update on this?

amkomatz avatar Nov 01 '20 06:11 amkomatz

Please we need this!.

Kishimotovn avatar Jan 10 '21 15:01 Kishimotovn

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

Maxim-Inv avatar Jan 11 '21 16:01 Maxim-Inv

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

bordunosp avatar Mar 05 '21 18:03 bordunosp

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

Maxim-Inv avatar Mar 05 '21 18:03 Maxim-Inv

@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

bordunosp avatar Mar 05 '21 18:03 bordunosp

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.

Maxim-Inv avatar Mar 05 '21 19:03 Maxim-Inv

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()"

bordunosp avatar Mar 05 '21 21:03 bordunosp

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.

Maxim-Inv avatar Mar 07 '21 06:03 Maxim-Inv

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 avatar Mar 07 '21 08:03 bordunosp

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() {
    ...
}

bordunosp avatar Mar 07 '21 10:03 bordunosp

@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?

patchthecode avatar Aug 28 '22 21:08 patchthecode

@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.

Maxim-Inv avatar Sep 21 '22 08:09 Maxim-Inv

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.

albertodebortoli avatar Mar 04 '24 18:03 albertodebortoli