Closed Prince2k3 closed 9 years ago
@Prince2k3 Thanks! Now, this library uses NSCalendar
's timezone, which the user specified at Settings. When do you want to set/get timezone?
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.
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
Yes ...that would be very nice setup!
OK! I will try to implement above feature!
Sweet! Thanks!
@Prince2k3, I have implemented features to set/get the time zone. Please check the playground at https://github.com/naoty/Timepiece/commit/24a117399b7c636ff6db9dace45952b89b4b02f2! If there is no problem, I will merge this and release as the next version.
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.
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
}
}
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.
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.
I added tests for above cases, which are all passed without any additional implementations. It looks fine. @Prince2k3, can I merge this branch?
Yes! ... I think it looks good as well!
@Prince2k3 Thanks!
First off. I like the progress of this library. It's very elegant. So to my issue....I think this is more a feature request then an issue. I was thinking would be very nice to be able to set / get Timezones. What do you think?