Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit d9c1758

Browse files
committed
Use full precision timestamps in JSON responses
Currently we store timestamps with microsecond precision (the default and maximum for PostgreSQL), but over the wire we only send milliseconds (the default for Rails). This is fine for most purposes, but as we're migrating data from forms-api to forms-admin at the moment it's helpful to get the full precision so we can easily compare the contents of the two databases without noise from truncated timestamps. This commit uses the ActiveSupport configuration parameter to change the `TimeWithZone#as_json` method to return all 6 digits of precision.
1 parent 5e7e9a0 commit d9c1758

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Application < Rails::Application
4242
# Skip views, helpers and assets when generating a new resource.
4343
config.api_only = true
4444

45+
# Include full precision of timestamps in JSON responses
46+
config.active_support.time_precision = 6
47+
4548
#### lOGGING #####
4649
# Include generic and useful information about system operation, but avoid logging too much
4750
# information to avoid inadvertent exposure of personally identifiable information (PII).

spec/requests/api/v1/pages_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
position: 1,
7171
routing_conditions: [],
7272
has_routing_errors: false,
73-
created_at: "2023-01-01T12:00:00.000Z",
74-
updated_at: "2023-01-01T12:00:00.000Z",
73+
created_at: "2023-01-01T12:00:00.000000Z",
74+
updated_at: "2023-01-01T12:00:00.000000Z",
7575
page_heading: nil,
7676
guidance_markdown: nil,
7777
is_repeatable: false).as_json)

0 commit comments

Comments
 (0)