From: Jim Cropcho Date: 2008-01-23T04:54:14+09:00 Subject: [PATCH] Friendlier methods to compare two Time objects ------=_Part_20674_19110150.1201031661158 Content-Type: multipart/alternative; boundary="----=_Part_20675_16080115.1201031661158" ------=_Part_20675_16080115.1201031661158 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, Currently, comparison of two Time objects is done via the >, < and <=> methods. Although they make sense in many contexts, here they are counterintuitive, because people do not normally think of a Time as being "greater than" or "less than" another time. Rather, words such as "before" and "after" are used. I propose the addition of "before?(another_time)" and "after?(another_time?)" as public instance methods for Class:Time. Examples: Time.now.after? Time.now+100 # => false Time.now.before ? Time.now+100 # => true As you can see, these methods can be read and written far more naturally, providing quicker development and easier maintenance. Like Matz, "I'm trying to make Ruby natural, not simple." Regards, Jim Cropcho ChangeLog entry: =========================== {DATE OF COMMIT} Jim Cropcho * time.c: added public instance methods "before?" and "after?". =========================== ------=_Part_20675_16080115.1201031661158 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello,

Currently, comparison of two Time objects is done via the >, < and <=> methods. Although they make sense in many contexts, here they are counterintuitive, because people do not normally think of a Time as being "greater than" or "less than" another time. Rather, words such as "before" and "after" are used.

I propose the addition of "before?(another_time)" and "after?(another_time?)" as public instance methods for Class:Time.

Examples:

Time.now.after? Time.now+100 # => false
Time.now.before ? Time.now+100 # => true

As you can see, these methods can be read and written far more naturally, providing quicker development and easier maintenance. Like Matz, "I'm trying to make Ruby natural, not simple."

Regards,
Jim Cropcho

ChangeLog entry:
===========================
{DATE OF COMMIT}  Jim Cropcho <jim.cropcho@gmail.com>

  * time.c: added public instance methods "before?" and "after?".
===========================
------=_Part_20675_16080115.1201031661158-- ------=_Part_20674_19110150.1201031661158 Content-Type: text/x-patch; name=ruby-before_and_after.patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_fbqv3vpy0 Content-Disposition: attachment; filename=ruby-before_and_after.patch SW5kZXg6IHRpbWUuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSB0aW1lLmMJKHJldmlzaW9uIDE1MTc0KQorKysg dGltZS5jCSh3b3JraW5nIGNvcHkpCkBAIC0xMDc4LDYgKzEwNzgsNjAgQEAKIAogLyoKICAqIGNh bGwtc2VxOgorICogIHRpbWUuYmVmb3JlPyhvdGhlcl90aW1lKQorICoKKyAqIFJldHVybiA8Y29k ZT50cnVlPC9jb2RlPiBpZiA8aT50aW1lPC9pPiBpcyBiZWZvcmUgPGk+b3RoZXJfdGltZTwvaT4s IG9yCisgKiA8Y29kZT5mYWxzZTwvY29kZT4gaWYgYWZ0ZXIgb3IgdGhlIHNhbWUgdGltZSBhcyA8 aT5vdGhlcl90aW1lPC9pPi4KKyAqLworCitzdGF0aWMgVkFMVUUKK3RpbWVfYmVmb3JlKFZBTFVF IHRpbWUxLCBWQUxVRSB0aW1lMikKK3sKKyAgICBzdHJ1Y3QgdGltZV9vYmplY3QgKnRvYmoxLCAq dG9iajI7CisKKyAgICBHZXRUaW1ldmFsKHRpbWUxLCB0b2JqMSk7CisgICAgaWYgKFRZUEUodGlt ZTIpID09IFRfREFUQSAmJiBSREFUQSh0aW1lMiktPmRmcmVlID09IHRpbWVfZnJlZSkgeworCQkJ R2V0VGltZXZhbCh0aW1lMiwgdG9iajIpOworCQkJaWYgKHRvYmoxLT50cy50dl9zZWMgPT0gdG9i ajItPnRzLnR2X3NlYykgeworCQkJCQlpZiAodG9iajEtPnRzLnR2X25zZWMgPCB0b2JqMi0+dHMu dHZfbnNlYykgcmV0dXJuIFF0cnVlOworCQkJCQlyZXR1cm4gUWZhbHNlOworCQkJfQorCQkJaWYg KHRvYmoxLT50cy50dl9zZWMgPCB0b2JqMi0+dHMudHZfc2VjKSByZXR1cm4gUXRydWU7CisJCQly ZXR1cm4gUWZhbHNlOworICAgIH0KKworICAgIHJldHVybiBRbmlsOworfQ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AgIHJiX2RlZmluZV9tZXRob2QocmJfY1RpbWUsICJ0b19pIiwgdGltZV90b19p LCAwKTsKICAgICByYl9kZWZpbmVfbWV0aG9kKHJiX2NUaW1lLCAidG9fZiIsIHRpbWVfdG9fZiwg MCk7CiAgICAgcmJfZGVmaW5lX21ldGhvZChyYl9jVGltZSwgIjw9PiIsIHRpbWVfY21wLCAxKTsK KyAgICByYl9kZWZpbmVfbWV0aG9kKHJiX2NUaW1lLCAiYmVmb3JlPyIsIHRpbWVfYmVmb3JlLCAx KTsKKyAgICByYl9kZWZpbmVfbWV0aG9kKHJiX2NUaW1lLCAiYWZ0ZXI/IiwgdGltZV9hZnRlciwg MSk7CiAgICAgcmJfZGVmaW5lX21ldGhvZChyYl9jVGltZSwgImVxbD8iLCB0aW1lX2VxbCwgMSk7 CiAgICAgcmJfZGVmaW5lX21ldGhvZChyYl9jVGltZSwgImhhc2giLCB0aW1lX2hhc2gsIDApOwog ICAgIHJiX2RlZmluZV9tZXRob2QocmJfY1RpbWUsICJpbml0aWFsaXplIiwgdGltZV9pbml0LCAw KTsK ------=_Part_20674_19110150.1201031661158--