Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fixed/stopwatch-sloth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Time search attribute values now keep sub-second precision, and setting one no longer raises `NoMethodError` when the application has not required `time`.
6 changes: 4 additions & 2 deletions temporalio/lib/temporalio/search_attributes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'temporalio/api'
require 'time'

module Temporalio
# Collection of typed search attributes.
Expand Down Expand Up @@ -142,8 +143,9 @@ def self._value_from_payload(payload)

# @!visibility private
def self._to_proto_pair(key, value)
# We use a default converter, but if type is a time, we need ISO format
value = value.iso8601 if key.type == IndexedValueType::TIME && value.is_a?(Time)
# We use a default converter, but if type is a time, we need ISO format with nanoseconds since the server keeps
# sub-second precision
value = value.iso8601(9) if key.type == IndexedValueType::TIME && value.is_a?(Time)

# Convert to payload
payload = Converters::PayloadConverter.default.to_payload(value)
Expand Down
17 changes: 17 additions & 0 deletions temporalio/test/client_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def test_lazy_connect
assert client.connection.connected?
end

exclude_from_cloud :needs_cloud_adaptation,
'Requires custom search attributes that the Cloud harness does not provision.'
def test_search_attribute_time_sub_second
env.ensure_common_search_attribute_keys

time = Time.at(1_800_000_000, 123_456_789, :nanosecond, in: 'UTC')
handle = env.client.start_workflow(
'does-not-exist',
id: "wf-#{SecureRandom.uuid}",
task_queue: "tq-#{SecureRandom.uuid}",
search_attributes: Temporalio::SearchAttributes.new({ ATTR_KEY_TIME => time })
)
assert_equal time, handle.describe.search_attributes&.[](ATTR_KEY_TIME)
ensure
handle&.terminate
end

exclude_from_cloud :needs_cloud_adaptation,
'Requires custom search attributes and a Go worker with Cloud TLS configuration.'
def test_describe
Expand Down
Loading