Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal]When bitemporal_at exists inside the nest, the specified date was not prioritized, so the date of the inner bitemporal_at is now prioritized. #121

Merged
merged 3 commits into from
Feb 28, 2023

Conversation

bonobono555
Copy link
Contributor

@bonobono555 bonobono555 commented Feb 8, 2023

Summary

I think it's unnatural that the given date is not given priority when bitemporal_at exists inside the nest, and I want to give priority to the date of the inner bitemporal_at

reason
valid_at and transaction_at behave to give priority to the inner date, but bitemporal_at does not give priority to the inner date, so I thought it would be more natural to match valid_at and transaction_at.

ex. inner valid_at takes precedence

ActiveRecord::Bitemporal.valid_at("2020/01/01") do
  puts Employee.valid_at("1999/01/01").to_sql
end
# => SELECT "employees".*
#      FROM "employees"
#     WHERE "employees"."transaction_from" <= '2023-02-20 05:21:24'   <- current time
#       AND "employees"."transaction_to"   >  '2023-02-20 05:21:24'   <- current time
#       AND "employees"."valid_from"       <= '1999-01-01 00:00:00'
#       AND "employees"."valid_to"         >  '1999-01-01 00:00:00'

bitemporal_at before

bitemporal_at does not take precedence

ActiveRecord::Bitemporal.valid_at("2020/01/01") do
  puts Employee.bitemporal_at("1999/01/01").to_sql
end
# => SELECT "employees".*
#      FROM "employees"
#     WHERE "employees"."transaction_from" <= '1999-01-01 00:00:00'
#       AND "employees"."transaction_to"   >  '1999-01-01 00:00:00'
#       AND "employees"."valid_from"       <= '2020-01-01 00:00:00'
#       AND "employees"."valid_to"         >  '2020-01-01 00:00:00'

bitemporal_at after

bitemporal_at takes precedence

ActiveRecord::Bitemporal.valid_at("2020/01/01") do
  puts Employee.bitemporal_at("1999/01/01").to_sql
end
# => SELECT "employees".*
#      FROM "employees"
#     WHERE "employees"."transaction_from" <= '1999-01-01 00:00:00'
#       AND "employees"."transaction_to"   >  '1999-01-01 00:00:00'
#       AND "employees"."valid_from"       <= '1999-01-01 00:00:00'
#       AND "employees"."valid_to"         >  '1999-01-01 00:00:00'

@bonobono555 bonobono555 requested review from osyo-manga and removed request for osyo-manga February 8, 2023 10:49
@bonobono555 bonobono555 marked this pull request as ready for review February 20, 2023 08:25
@auto-assign auto-assign bot requested a review from tknzk February 20, 2023 08:25
Copy link
Collaborator

@osyo-manga osyo-manga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! :)

@bonobono555 bonobono555 removed the request for review from tknzk February 21, 2023 02:39
@wata727 wata727 self-requested a review February 21, 2023 04:43
end

if !ActiveRecord::Bitemporal.ignore_valid_datetime?
relation = relation.valid_at(ActiveRecord::Bitemporal.valid_datetime || datetime)
relation = relation.valid_at(datetime || ActiveRecord::Bitemporal.valid_datetime || Time.current)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling Time.current on valid time and transaction time respectively can give different results in milliseconds. Is it better to use the same time? e.g.

current_time = Time.current

if !ActiveRecord::Bitemporal.ignore_transaction_datetime?
  relation = relation.transaction_at(datetime || ActiveRecord::Bitemporal.transaction_datetime || current_time)
end

if !ActiveRecord::Bitemporal.ignore_valid_datetime?
  relation = relation.valid_at(datetime || ActiveRecord::Bitemporal.valid_datetime || current_time)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wata727
thank you.
Fixed as suggested.

Copy link
Contributor

@wata727 wata727 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@bonobono555 bonobono555 merged commit 97ddc14 into kufu:master Feb 28, 2023
@Dooor Dooor mentioned this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants