datesmalltalkvisualworks

Can I compare two dates in Smalltalk?


I have two dates which I need to compare, if one is past second. That means:

date1 := Date newDay: 10 month: 12 year: 2017
date2 := Date newDay: 1 month: 1 year: 2020

So in this case date2 is past date1, so I need this to be true.
But

date1 := Date newDay: 10 month: 12 year: 2017
date2 := Date newDay: 3 month: 7 year: 2015

should return false.

Anyone got hints? Appreciate!


Solution

  • I guess this depends on which dialect you are using, but ANSI standard already defines < for DateAndTime which seems similar to Date. I tried your code in Pharo and Dolphin and date1 < date2 works just fine for your needs (even if Date instantiation in Dolphin is a little bit different).