Giter Club home page Giter Club logo

Comments (14)

naoty avatar naoty commented on June 14, 2024

@Prince2k3 Thanks! Now, this library uses NSCalendar's timezone, which the user specified at Settings. When do you want to set/get timezone?

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

So I have a scenario where I would need to check the date at a certain timezone because a server only acts within it. Like for instance checking to see if a transaction is valid before a certain time in CST.

from timepiece.

naoty avatar naoty commented on June 14, 2024

Oh, I see. For example, is it favorable for you to set/get timezone like below?

let cst = NSTimeZone(abbreviation: "CST")
let lastWeekInCST = 1.week.ago.in(timezone: cst)

lastWeekInCST.timezone
//=> cst

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

Yes ...that would be very nice setup!

from timepiece.

naoty avatar naoty commented on June 14, 2024

OK! I will try to implement above feature!

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

Sweet! Thanks!

from timepiece.

naoty avatar naoty commented on June 14, 2024

@Prince2k3, I have implemented features to set/get the time zone. Please check the playground at 24a1173! If there is no problem, I will merge this and release as the next version.

from timepiece.

naoty avatar naoty commented on June 14, 2024

I noticed that the calculation and comparison of dates with different time zones are not implemented. After they are implemented, I will release this feature.

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

Hey tested the the timezone feature and it works. Yeah if there is any way to sort the length of this code even more. Then I'm all for it!

extension NSDate {
    func canCancel() -> Bool {
        var currentDate = NSDate().change(timeZone: NSTimeZone(abbreviation: "CST")!)

        if currentDate.day == day && (currentDate.hour < 13 || (currentDate.hour > 13 && hour > 13)) {
            return true
        } else if (currentDate.timeIntervalSinceDate(self) < 86400) && (hour >= 13) && currentDate.hour < 13 {
            return true
        }
        return false
    }
}

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

What did you have in mind for calculation and comparison? So far I seem to do that just fine if I make sure that the timezones are the same.

from timepiece.

naoty avatar naoty commented on June 14, 2024

For example, I think now == now.change(timeZone: cst) should be true. But, actually the result is false in current implementation. When we calculate or compare dates with different time zones, we should change the time zone of either date into one of another date.

from timepiece.

naoty avatar naoty commented on June 14, 2024

I added tests for above cases, which are all passed without any additional implementations. It looks fine. @Prince2k3, can I merge this branch?

from timepiece.

Prince2k3 avatar Prince2k3 commented on June 14, 2024

Yes! ... I think it looks good as well!

from timepiece.

naoty avatar naoty commented on June 14, 2024

@Prince2k3 Thanks!

from timepiece.

Related Issues (20)

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.