Some utility functions around gregor
1 Utility functions
date->moment
moment->date
racket-date?
8.18

Some utility functions around gregor🔗ℹ

Hans Dijkema <hans@dijkewijk.nl>

See also gregor module.

This module provides some utility functions around the gregor date module

1 Utility functions🔗ℹ

procedure

(date->moment dt)  moment?

  dt : (or/c date? date*?)
Converts a racket "date" or "date*" structure to a gregor "moment". When it converts, it will assumes two kinds of dates.

  • The first being a standard racket date structure with a time zone offset.

  • The second for a date* structure, that will hold a named local timezone or ’UTC’.

This function will check if the date* structure is UTC time or local timezone. If it is local timezone, it will use the function "(system-tzid)" of tzinfo to determine the local timezone id, that can be used to create a new gregor "moment".

As date* will be either localtime or UTC, we’re working with what we got. We can recognize UTC, but the timezone name will be something OS specific, e.g. on a dutch windows system: "West-Europa (zomertijd)". This is reported e.g. in the windows powershell command:

> get-timezone:
 
  Id                         : W. Europe Standard Time
  DisplayName                : (UTC+01:00) Amsterdam,Berlijn,Bern,Rome,Stockholm,Wenen
  StandardName               : West-Europa (standaardtijd)
  DaylightName               : West-Europa (zomertijd)
  BaseUtcOffset              : 01:00:00
  SupportsDaylightSavingTime : True

But, as the racket standard date functions only work with UTC and localtime, we can request the current timezone tzinfo’s "(system-tzid)" for localtime and use UTC for univeral time.

procedure

(moment->date m)  date*?

  m : moment?
Converts a gregor "moment" to a standard racket "date*".

procedure

(racket-date? d)  boolean?

  d : any/c?
Returns #t, if d is of racket’s standard type "date" or racket{date*}.