--- Begin Message ---#hasSameDayAs: ----------------- Benoît St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean Instagram: Chef_Benito IRC: lamneth Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein)From: Alistair Grant <akgrant0...@gmail.com> To: Any question about pharo is welcome <pharo-users@lists.pharo.org> Sent: Tuesday, November 21, 2017 12:07 PM Subject: Re: [Pharo-users] Timespan translateToUTC problematic On 20 November 2017 at 09:16, Sven Van Caekenberghe <s...@stfx.eu> wrote: > > We can discuss about this ad infinitum. I think we all agree that > there are 2 views (abstract calendar date and concrete time > interval/span, which requires a TZ), as well as 2 possible ways to > deal with the second case (TZ inside date or as context outside of the > date). Right, I think changing things now will be quite a bit of work. However there are a couple of things we can do to make life a bit easier: 1. Add a method that facilitates TZ independent comparisons. 2. Add a bit more information in the class comments. I've named the method #dmyEquals: below, although I don't particularly like it. If anyone has a better idea, please reply. I've also added some proposed text for the class comments. If I don't hear back in a couple of days I'll submit a PR (with automated tests). Cheers, Alistair ---- dmyEquals: aDate "Perform a time zone independent comparison of the dates, i.e. only compare day, month and year" ^self year = aDate year and: [ self monthIndex = aDate monthIndex and: [ self dayOfMonth = aDate dayOfMonth ] ] ---- Class comment: Instances of Date are Timespans with duration of 1 day. Their default creation assumes a start of midnight in the local time zone. !Comparing Dates We tend to use dates in one of two modes: - Time zone dependent - Time zone independent In the first instance, dates are only the same if they are in the same time zone (otherwise they are two different 24 hour periods). This is the default behaviour of Date. In the second, comparison is only interested in whether the day, month and year are the same. As an example, take someone's birthday. If I want to know whether we were born on the same day, I will want to compare dates without time zones. If I want to know if it is currently their birthday where they are, I'll want to use time zones. [[[language=smalltalk | birthday1 birthday2 | birthday1 := (DateAndTime fromString: '2018/01/01T00:00:00+10') asDate. birthday2 := (DateAndTime fromString: '2018/01/01T00:00:00+01') asDate. "Is it person 1's birthday now? (where they live: UTC+10)" birthday1 includes: DateAndTime now. "Do person 1 and person 2 have the same birthday?" birthday1 dmyEquals: birthday2. ]]]
--- End Message ---
Re: [Pharo-users] Timespan translateToUTC problematic
Benoit St-Jean via Pharo-users Tue, 21 Nov 2017 16:47:30 -0800
- Re: [Pharo-users] Timespan tra... Peter Uhnák
- Re: [Pharo-users] Timespan... Sven Van Caekenberghe
- Re: [Pharo-users] Tim... Alistair Grant
- Re: [Pharo-users]... Sven Van Caekenberghe
- Re: [Pharo-users]... Alistair Grant
- Re: [Pharo-users]... Ben Coman
- Re: [Pharo-users]... Sven Van Caekenberghe
- Re: [Pharo-users]... Pavel Krivanek
- Re: [Pharo-users]... Alistair Grant
- Re: [Pharo-users]... Sven Van Caekenberghe
- Re: [Pharo-users]... Benoit St-Jean via Pharo-users
- Re: [Pharo-users]... Sean P. DeNigris
- Re: [Pharo-users]... Benoit St-Jean via Pharo-users
- Re: [Pharo-users]... Ben Coman
- Re: [Pharo-users]... Alistair Grant
- Re: [Pharo-users] Timespan translateTo... Alistair Grant
- Re: [Pharo-users] Timespan transla... Stephane Ducasse
- Re: [Pharo-users] Timespan translateToUTC p... Sven Van Caekenberghe
- Re: [Pharo-users] Timespan translateToUTC p... Richard A. O'Keefe
- Re: [Pharo-users] Timespan translateTo... David T. Lewis
- Re: [Pharo-users] Timespan transla... Ben Coman