> On 21 Nov 2017, at 18:07, Alistair Grant <akgrant0...@gmail.com> wrote:
> 
> 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.

#equals:
#calendarEquals:
#equalIgnoreTimezone:

> I've also added some proposed text for the class comments.

More comments are always good.

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


Reply via email to