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

[Good First Issues]: implement function "convert_timezone" - 7 points #438

Closed
Tracked by #355
Michaelg22 opened this issue Feb 20, 2023 · 6 comments · Fixed by #597
Closed
Tracked by #355

[Good First Issues]: implement function "convert_timezone" - 7 points #438

Michaelg22 opened this issue Feb 20, 2023 · 6 comments · Fixed by #597
Assignees
Labels

Comments

@Michaelg22
Copy link
Contributor

Michaelg22 commented Feb 20, 2023

Motivation

Vanus Functions are a series of pre-built functions worked within Vanus transformer. By choosing a function, users can specify the way that events will be changed.

It will be a good start if you decide to contribute to Vanus codes.

Details

Function name: convert_timezone

Args

  • sourceJsonPath: The source value can be of type string, date, or timestamp.

  • fromTimeZone: Source value timezone. If nothing is specified, the default timezone is UTC.

  • toTimeZone: Timezone to be converted to. If nothing is specified, the default timezone is UTC.

  • targetJsonPath: The target path.

  • dateTimeFormat: (Optional) A format string for the date. If the format isn't specified, the default format is used: yyyy-mm-dd HH:MM:SS.

Description

The function is used to convert the time in a specific TimeZone from the source JSON path to time in another TimeZone, and assign the converted time to a target JSON path.
The time format will be yyyy-mm-dd HH:MM:SS if users don't specify it.

Example

{
    "specversion": "1.0",
    "type": "com.example.someevent",
    "source": "/mycontext",
    "subject": null,
    "id": "C234-1234-1234",
    "time": "2018-04-05T17:31:00Z",
    "comexampleextension1": "value",
    "comexampleothervalue": 5,
    "datacontenttype": "application/json",
    "data": {
        "appinfoA": "2021-08-29 12:01:10"
    }
}

After the function.

"pipeline": [
    {"command":["convert_timezone", "$.data.appinfoA", "CET", "UTC", "yyyy-mm-dd HH:MM:SS"]}
]

The transformed event should look like this:

{
    "specversion": "1.0",
    "type": "com.example.someevent",
    "source": "/mycontext",
    "subject": null,
    "id": "C234-1234-1234",
    "time": "2018-04-05T17:31:00Z",
    "comexampleextension1": "value",
    "comexampleothervalue": 5,
    "datacontenttype": "application/json",
    "data": {
        "appinfoA": "2021-08-29 10:01:10"
    }
}
   

How to implement

  1. Fork the vanus repository.
  2. Create a branch function-convert_timezone
  3. Create convert_timezone.go under internal/primitive/transform/action/datatime, and then implement the function.
  4. Create convert_timezone_test.go under internal/primitive/transform/action/datatime for unit test.
  5. Register your function in internal/primitive/transform/runtime/init.go.
  6. Submit your PR

Contribution points

Each issue counts specific points based on its difficulty. Contributors earn the corresponding points if they solve that issue. Contribution points are used to describe the contributions contributors have made. They can also be used to get rewards when there are community events.

This issue counts 7 points.

How to claim to solve the issue

If you want to implement this function, please leave a comment in this issue like:

I'd like to implement this function, please assign this issue to me.

Vanus community will assign the issue to you on time.

@Michaelg22 Michaelg22 added help-wanted Extra attention is needed good first issue labels Feb 20, 2023
@hi-malik
Copy link

hi-malik commented Feb 20, 2023

I'd like to implement this function, Please assign this issue to me!

@Michaelg22
Copy link
Contributor Author

Hi @hi-malik Thanks for your interest I have assigned it to you. please join our slack community for better communication

@Michaelg22
Copy link
Contributor Author

Sorry about that please make sure to move the function to internal/primitive/transform/action/datatime

@soumyadeep589
Copy link
Contributor

I'd like to implement this function, Please assign this issue to me!

@soumyadeep589
Copy link
Contributor

Can you please review the example of the transformed event once? Because to my understanding, CET time is 2 hours ahead of UTC time.

@ifplusor
Copy link
Collaborator

Can you please review the example of the transformed event once? Because to my understanding, CET time is 2 hours ahead of UTC time.

@soumyadeep589 You're right, it's our mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants