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 |
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? 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 > > |
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: |
We generally use upTo: when excluding like in Stream and primesUpTo: Le sam. 11 mai 2019 à 20:05, Chris Cunningham <[hidden email]> a écrit :
|
Free forum by Nabble | Edit this page |