round_timestamps.rb

Path: lib/sequel/extensions/round_timestamps.rb
Last Update: Sun Oct 02 21:06:53 +0000 2016

frozen-string-literal: true

The round_timestamps extension will automatically round timestamp values to the database‘s supported level of precision before literalizing them.

For example, if the database supports millisecond precision, and you give it a Time value with microsecond precision, it will round it appropriately:

  Time.at(1405341161.917999982833862)
  # default: 2014-07-14 14:32:41.917999
  # with extension: 2014-07-14 14:32:41.918000

The round_timestamps extension correctly deals with databases that support millisecond or second precision. In addition to handling Time values, it also handles DateTime values and Sequel::SQLTime values (for the TIME type).

To round timestamps for a single dataset:

  ds = ds.extension(:round_timestamps)

To round timestamps for all datasets on a single database:

  DB.extension(:round_timestamps)

Related module: Sequel::Dataset::RoundTimestamps

[Validate]