Postgres has a fantastic collection of column types
that makes it easy to store custom data.
One such type are Ranges which allow you to store a range of values.
For example, you can store a range of dates or a range of integers.
When it comes to storing a range of timestamps, Postgres provides the tsrange
and tstzrange column types which store a range of timestamps with
and without timezones respectively.
Let’s create a column in a Rails module to store a range of timestamps.
Now let’s store a range of timestamps in this column.
This works as expected.
However, if we set a timezone in the application config
(and then make tsrange timezone aware),
we get a TypeError.
Now let’s try again!
Thanks to this PR,
the app timezone is now retained when storing a range of timestamps.
Let’s try again!