Chronos is one of the many Smalltalk-related blogs syndicated on Planet Smalltalk
χρόνος

Discussion of the Essence# programming language, and related issues and technologies.

Blog Timezone: America/Los_Angeles [Winter: -0800 hhmm | Summer: -0700 hhmm] 
Your local time:  

2006-01-09

Chronos: A Few Comparative Examples

The home page for the Joda Date/Time Library presents some examples intended to demonstrate the "look and feel" of using Joda-Time. To see the Joda examples, click the link in the previous sentence.

Here are the equivalent examples using Chronos:

daysToNewYear: fromDate [Alternative 1]
    ^CalendarDuration days: (fromDate daysInYear - fromDate dayOfYear + 1)

daysToNewYear: fromDate [Alternative 2]
    ^CalendarDuration days: (fromDate daysUntil: (fromDate nextYear withDayOfYear: 1))

isRentalOverdue: datetimeRented [Alternative 1]
    "Answer whether a rental made on <datetimeRented> is now overdue."
    ^datetimeRented + 2.5 days < DateAndTime now

isRentalOverdue: datetimeRented [Alternative 2]
    "Answer whether a rental made on <datetimeRented> is now overdue."
    ^datetimeRented + (CivilDuration days: 2 hours: 12) < DateAndTime now

joinedInLastThreeMonths: datetimeJoined
    "Answer whether the <datetimeJoined> is within the past three months."
    ^(DateAndTime now withDuration: -3 months) includes: datetimeJoined

getBirthMonthText: dateOfBirth forLocale: localeKey
    "Answer the name of the month of <dateOfBirth> according to the locale identified by the <localeKey>."
    ^dateOfBirth
            forLocale: localeKey
            monthNameIfResolvable:
                [:monthName | monthName]
            ifNot:
                [dateOfBirth monthName]


No comments: