Skip to content

Parsing the date/time parameter depends on the local zone setting in the operating system, not in the Rails application #101

@sergey-arkhipov

Description

@sergey-arkhipov

Basic Info

  • rails_param Version:
  • Ruby Version: 3.2.2
  • Rails Version: 7.1.1

Description

Using params! Time gives incorrect results in case of parameter parsing without specifying time zone.
In this case the result depends on the local zone setting on the running computer/docker, but should be determined by the time zone setting in the application configuration.

Steps for reproduction

For the same application with time zone settings:

  • run in docker with operation system time zone
  • run in docker with operation system without time zone

Rails console example

Rails Time zone is set, container time zone - different (not set)

Applications are different in this example, but it is not a key.

[4] pry(main)> param = '01.01.2023 00:00:00'
=> "01.01.2023 00:00:00"
[5] pry(main)> options = { format: '%e.%m.%Y %H:%M:%S'}
=> {:format=>"%e.%m.%Y %H:%M:%S"}
[6] pry(main)> type = Time
=> Time
[7] pry(main)> type.strptime(param, options[:format])
=> 2023-01-01 00:00:00 +0000
[8] pry(main)> "01.01.2023 00:00:00".in_time_zone
=> Sun, 01 Jan 2023 00:00:00.000000000 MSK +03:00
[9] pry(main)> Time.parse(param)
=> 2023-01-01 00:00:00 +0000
[10] pry(main)> Problems::Application.config.time_zone
=> "Europe/Moscow"

Rails Time zone is set, container time zone - the same

>> param = '01/01/2023 00:00'
=> "01/01/2023 00:00"
>> option = { format: '%e.%m.%Y %H:%M:%S'}
=> {:format=>"%e.%m.%Y %H:%M:%S"}
>> type = Time
=> Time
>> options = { format: '%e.%m.%Y %H:%M:%S'}
=> {:format=>"%e.%m.%Y %H:%M:%S"}
>> param = '01.01.2023 00:00:00'
=> "01.01.2023 00:00:00"
>> type.strptime(param, options[:format])
=> 2023-01-01 00:00:00 +0300
>> Souz::Application.config.time_zone
=> "Europe/Moscow"
>> param.in_time_zone
=> Sun, 01 Jan 2023 00:00:00.000000000 MSK +03:00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions