Timespan>>datesDo: - is this a bug?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
cbc
Reply | Threaded
Open this post in threaded view
|

Timespan>>datesDo: - is this a bug?

cbc
So, this code:
   Date today asMonth datesDo: [:date| Transcript cr; show: date yyyymmdd]
prints out each day in the month.  That is what I'd expect.

This code:
  |mth|
  mth := Date today asMonth.
  (mth start asDate to: mth end asDate) datesDo: [:date| Transcript cr; show: date yyyymmdd]
does not print the last date.

This has bitten me.  If I add a nanosecond onto the end date (mth end asDate + 1) it does include the last date - but that is ugly.  And dangerous if I have other code that carefully picks the following date start to work around this oddity.

Thoughts?

-cbc


Reply | Threaded
Open this post in threaded view
|

Re: Timespan>>datesDo: - is this a bug?

Levente Uzonyi
On Fri, 10 May 2019, Chris Cunningham wrote:

> So, this code:   Date today asMonth datesDo: [:date| Transcript cr; show: date yyyymmdd]
> prints out each day in the month.  That is what I'd expect.
>
> This code:
>   |mth|
>   mth := Date today asMonth.
>   (mth start asDate to: mth end asDate) datesDo: [:date| Transcript cr; show: date yyyymmdd]
> does not print the last date.
>
> This has bitten me.  If I add a nanosecond onto the end date (mth end asDate + 1) it does include the last date - but that is ugly.  And dangerous if I have other code that carefully picks the following date start to work around this oddity.
>
> Thoughts?
I wrote a mail about this just two months ago[1]. Timespan, unlike
Interval, is a right-open interval. It has to be in order to have the
expected length. Date(Timespan) >> #to: will create a Timespan.

Levente

[1] http://forum.world.st/Testing-out-new-UTCDateAndTime-in-Squeak-5-3-alpha-td5096623.html

>
> -cbc
>
>

cbc
Reply | Threaded
Open this post in threaded view
|

Re: Timespan>>datesDo: - is this a bug?

cbc
That does explain it.  So, datesDo: is fine.

Timespan>>to: is the method at issue.  The right-open intenterval is what tripped me up. Other implementations of #to: are right closed: (1 to: 2) includes 2, for instance, whereas (Date yesterday to: Date today) does not include today.

Time to: makes sense to me: '01:00:00' asTime to: '02:00:00' asTime being 1 hour makes sense to me, since it is a particular point in time to another particular point in time.
The Day to Day - I guess just assuming the 2nd day means the beginning of the day instead of the end of the day is what gets me.

I'd excpect Date today to: Date today to be today - not an empty timespan.

Maybe I just need to get over it.
But what I'd expect is the the end part of the timespan #to: to use the end of the ending timespan,if possible.

Thanks,
cbc

On Fri, May 10, 2019 at 3:40 PM Levente Uzonyi <[hidden email]> wrote:
On Fri, 10 May 2019, Chris Cunningham wrote:

> So, this code:   Date today asMonth datesDo: [:date| Transcript cr; show: date yyyymmdd]
> prints out each day in the month.  That is what I'd expect.
>
> This code:
>   |mth|
>   mth := Date today asMonth.
>   (mth start asDate to: mth end asDate) datesDo: [:date| Transcript cr; show: date yyyymmdd]
> does not print the last date.
>
> This has bitten me.  If I add a nanosecond onto the end date (mth end asDate + 1) it does include the last date - but that is ugly.  And dangerous if I have other code that carefully picks the following date start to work around this oddity.
>
> Thoughts?

I wrote a mail about this just two months ago[1]. Timespan, unlike
Interval, is a right-open interval. It has to be in order to have the
expected length. Date(Timespan) >> #to: will create a Timespan.

Levente

[1] http://forum.world.st/Testing-out-new-UTCDateAndTime-in-Squeak-5-3-alpha-td5096623.html

>
> -cbc
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Timespan>>datesDo: - is this a bug?

Nicolas Cellier
We generally use upTo: when excluding like in Stream and primesUpTo:

Le sam. 11 mai 2019 à 20:05, Chris Cunningham <[hidden email]> a écrit :
That does explain it.  So, datesDo: is fine.

Timespan>>to: is the method at issue.  The right-open intenterval is what tripped me up. Other implementations of #to: are right closed: (1 to: 2) includes 2, for instance, whereas (Date yesterday to: Date today) does not include today.

Time to: makes sense to me: '01:00:00' asTime to: '02:00:00' asTime being 1 hour makes sense to me, since it is a particular point in time to another particular point in time.
The Day to Day - I guess just assuming the 2nd day means the beginning of the day instead of the end of the day is what gets me.

I'd excpect Date today to: Date today to be today - not an empty timespan.

Maybe I just need to get over it.
But what I'd expect is the the end part of the timespan #to: to use the end of the ending timespan,if possible.

Thanks,
cbc

On Fri, May 10, 2019 at 3:40 PM Levente Uzonyi <[hidden email]> wrote:
On Fri, 10 May 2019, Chris Cunningham wrote:

> So, this code:   Date today asMonth datesDo: [:date| Transcript cr; show: date yyyymmdd]
> prints out each day in the month.  That is what I'd expect.
>
> This code:
>   |mth|
>   mth := Date today asMonth.
>   (mth start asDate to: mth end asDate) datesDo: [:date| Transcript cr; show: date yyyymmdd]
> does not print the last date.
>
> This has bitten me.  If I add a nanosecond onto the end date (mth end asDate + 1) it does include the last date - but that is ugly.  And dangerous if I have other code that carefully picks the following date start to work around this oddity.
>
> Thoughts?

I wrote a mail about this just two months ago[1]. Timespan, unlike
Interval, is a right-open interval. It has to be in order to have the
expected length. Date(Timespan) >> #to: will create a Timespan.

Levente

[1] http://forum.world.st/Testing-out-new-UTCDateAndTime-in-Squeak-5-3-alpha-td5096623.html

>
> -cbc
>
>