Giter Club home page Giter Club logo

swiftychrono's People

Contributors

jerrywell avatar tomyeh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftychrono's Issues

Crash for "6 June 2010"

Cool project. Thanks for your work on this. Dates entered like "June 6 2010" work great. "6 June 2010" however crashes.

Time Zone issues

So I realized that when parsing and using a refDate such as now Date(), the parsed result is in UTC timezone. So if i say 10pm today, it would parsed to 10pm today in UTC/GMT zone.

I tried to compensate this by calculating the different in my current time zone and UTC/GMT by using NSTimeZone.system.secondsFromGMT(for: currentDate), but when using options like forward date only, it creates problems. For example, its 4pm GMT, and 8AM PT, If I were in PT and say 10 AM today, it would mean in 2 hours, however since its parsed in UTC/GMT, it would be in 18 hours

*******sorry my mistake this issue is NON-EXISTENT ************

SwiftyChrono - It gives from different timezone. Is there any option to change the timezone ?

how to change the time zone?

right now, I'm passing refdate as my local time
so in some scenarios it is showing right and some it shows according to different timezone.

import SwiftyChrono

extension Date {

    // Convert local time to UTC (or GMT)
    func toGlobalTime() -> Date {
        let timezone = TimeZone.current
        let seconds = -TimeInterval(timezone.secondsFromGMT(for: self))
        return Date(timeInterval: seconds, since: self)
    }

    // Convert UTC (or GMT) to local time
    func toLocalTime() -> Date {
        let timezone = TimeZone.current
        let seconds = TimeInterval(timezone.secondsFromGMT(for: self))
        return Date(timeInterval: seconds, since: self)
    }

}

let chrono = Chrono()
chrono.parse(text: "Bring a book tomorrow")

let refDate = Date().toLocalTime()
let val = chrono.parse(text: "Bring a book tomorrow", refDate: refDate)
let date = chrono.parseDate(text: "tomorrow ",refDate: refDate)

let date1 = chrono.parseDate(text: "at 5 PM",refDate: refDate)
let date2 = chrono.parseDate(text: "in 2 minutes",refDate: refDate)

print(date)
print(date1)
print(date2)

Output-

Optional(2019-12-28 06:30:00 +0000) //different time zone
Optional(2019-12-27 11:30:00 +0000) //different time zone
Optional(2019-12-27 15:49:03 +0000) //right

Screenshot 2019-12-27 at 3 53 37 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.