Skip to content

Rails/TimeZone cop should allow Time.parse against a fixed string which includes a timezone specifier (bis) #800

Closed
@inkstak

Description

Is your feature request related to a problem? Please describe.

Similar to #440, we are often use this construct in tests :

Time.parse("2022-10-30 00:00:00 CEST +02:00")

It's especially usefull for explicit summer/winter time :

Time.parse("2022-10-30 00:00:00 CEST +02:00")
 => 2022-10-30 00:00:00 +0200

Time.parse("2022-10-31 00:00:00 CET +01:00")
 => 2022-10-31 00:00:00 +0100

Describe the solution you'd like

If detecting zones abbreviations might be too overwhelming, the cop should be able to detect and allow time offsets from UTC.

Similar to #441 :

-       TIMEZONE_SPECIFIER = /[A-z]/.freeze
+       TIMEZONE_SPECIFIER = /([A-z]|[+-]\d{2}:\d{2})\Z/.freeze

        def attach_timezone_specifier?(date)
-          date.respond_to?(:value) && TIMEZONE_SPECIFIER.match?(date.value.to_s[-1])
+          date.respond_to?(:value) && TIMEZONE_SPECIFIER.match?(date.value.to_s)
        end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions