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

Add timezone support for parse_timestamp #962

Closed
sandervandegeijn opened this issue Jul 29, 2024 · 6 comments · Fixed by #1207
Closed

Add timezone support for parse_timestamp #962

sandervandegeijn opened this issue Jul 29, 2024 · 6 comments · Fixed by #1207
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library

Comments

@sandervandegeijn
Copy link

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Use Cases

I have a timestamp in localtime. Vector assumes it is UTC, offsetting the time with 2 hours (CEST currently, Europe/Amsterdam). Adding a timezone parameter can solve this.

Attempted Solutions

Offsetting by hand, but we have summertime and wintertime...

Proposal

Implement timezone parameter

References

No response

Version

0.39

@sandervandegeijn sandervandegeijn added the type: feature A value-adding code addition that introduce new functionality. label Jul 29, 2024
@jszwedko
Copy link
Member

I think this would be useful to have at the function level, but just a note that it is possible to configure the timezone on the remap the transform. That should be used by parse_timestamp.

I'll move this request to the VRL repository.

@jszwedko jszwedko transferred this issue from vectordotdev/vector Jul 29, 2024
@jszwedko jszwedko added the vrl: stdlib Changes to the standard library label Jul 29, 2024
@titaneric
Copy link
Contributor

titaneric commented Dec 29, 2024

Hi, I just dig into parse_timestamp and it do have the timezone test.

        parse_text_with_tz {
            args: func_args![
                value: "16/10/2019:12:00:00",
                format:"%d/%m/%Y:%H:%M:%S"
            ],
            want: Ok(value!(
                DateTime::parse_from_rfc2822("Wed, 16 Oct 2019 10:00:00 +0000")
                    .unwrap()
                    .with_timezone(&Utc)
            )),
            tdef: TypeDef::timestamp().fallible(),
            tz: TimeZone::Named(chrono_tz::Europe::Paris),
        }

I also notice that timezone could be set in vector's config. Default value for timezone is Local, which is the timezone configured on the machine.

Could you provide example and its expected output?

@jszwedko
Copy link
Member

jszwedko commented Jan 2, 2025

@sandervandegeijn I believe we want the ability to provide a timezone to parse_timestamp to use when there is no timezone encoded in the input. For example: parse_timestamp(value: "16/10/2019:12:00:00", format: "%d/%m/%Y:%H:%M:%S", timezone: "Europe/Paris"). This would be used in place of whatever the default timezone on the system is (or the one specified in the Vector configuration at the global or remap transform level)

@pront
Copy link
Member

pront commented Jan 2, 2025

Hi, I just dig into parse_timestamp and it do have the timezone test.

        parse_text_with_tz {
            args: func_args![
                value: "16/10/2019:12:00:00",
                format:"%d/%m/%Y:%H:%M:%S"
            ],
            want: Ok(value!(
                DateTime::parse_from_rfc2822("Wed, 16 Oct 2019 10:00:00 +0000")
                    .unwrap()
                    .with_timezone(&Utc)
            )),
            tdef: TypeDef::timestamp().fallible(),
            tz: TimeZone::Named(chrono_tz::Europe::Paris),
        }

I also notice that timezone could be set in vector's config. Default value for timezone is Local, which is the timezone configured on the machine.

Could you provide example and its expected output?

Hi @titaneric, does this comment answer your questions? We basically have different cases (encoded timezone, configured timezone, suggested timezone parameter)

@titaneric
Copy link
Contributor

Hi @titaneric, does this #962 (comment) answer your questions?

Yes, I think I could give it a try

@sandervandegeijn
Copy link
Author

Fantastic, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A value-adding code addition that introduce new functionality. vrl: stdlib Changes to the standard library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants