This patch creates a module called Temporal which contains functionality useful to classes which define temporal objects,
such as dates and times. However, its intended scope is *not* limited to object comparison. It is handy in this regard,
though, because it addresses differences between languages, as several in the forum thread have noted:
http://www.ruby-forum.com/topic/139881
The module is added to the compilation configuration, and unit tests are included, all of which pass. Documentation
has also been written, and is included in the source with proper formatting. The module is mixed-in the classes Time
and Date (and DateTime, via extension).
The module does not include the methods past? and present?, as intended, because the means of determining "now"
is different even at the conceptual level between temporal classes. For example, "now" to Time is the number
of microseconds after epoch, but "now" to Date is the current calendar date. It is my opinion that
past?/present?/future? functionality should be implemented at the class level.
Today, Vladimir submitted a patch:
http://www.ruby-forum.com/topic/141085
Which highlights the sort of issues that can arise through the use of imprecise vocabulary in temporal comparison. For
example, it's conceivable a developer might attempt
some_time <=> 10039483
but they would certainly be much less likely to try
some_time.before? 10039483
because the vocabulary more precisely describes what the program is doing.
Please give my concept and source code consideration for being entered into the ruby core, and suggest
modifications/additions at will.
Jim Cropcho
CHANGELOG entry:
===========================
{DATE OF COMMIT} Jim Cropcho <jim.cropcho@gmail.com>
* temporal.c: created Temporal module for temporal object comparison.
* time.c: included Temporal module in Time class
* inits.c: Temporal module is initialized
* lib/date.rb: included Temporal module in Date class
* include/ruby/intern.h: initialized temporalint function
* include/ruby/ruby.h: initialized RUBY_EXTERN VALUE rb_mTemporal
* common.mk: added temporal.c and dependencies for compiling under make
* test/ruby/test_temporal.rb: created test suite for all Temporal module methods
===========================
|