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

DynamoDbAutoGeneratedTimestampAttribute custom date format and time zone #5062

Open
2 tasks
chrisbloe-nhse opened this issue Apr 3, 2024 · 3 comments
Open
2 tasks
Assignees
Labels
dynamodb-enhanced feature-request A feature should be added or improved. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@chrisbloe-nhse
Copy link

Describe the feature

The @DynamoDbAutoGeneratedTimestampAttribute annotation allows an Instant to be stored in DynamoDB as a String, however, the format of this string is fixed to (e.g.) 2023-06-06T18:16:40.632760903Z.

I have a requirement to store the date in a different format e.g. 2023-06-06T18:16:40+01:00.

Use Case

I have tried the following:

    @DynamoDbAttribute("CreatedAt")
    @DynamoDbAutoGeneratedTimestampAttribute
    @DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
    @DynamoDbConvertedBy(OffsetDateTimeAsStringAttributeConverter.class)
    public OffsetDateTime getCreatedAt() {
        return createdAt;
    }

However @DynamoDbAutoGeneratedTimestampAttribute requires the method to return an Instant, leaving no easy way of specifying the format of the auto generated time.

Proposed Solution

A nice way to achieve this would be to allow the annotation user to specify a format and time zone e.g.

@DynamoDbAutoGeneratedTimestampAttribute(format=DateTimeFormatter.ISO_OFFSET_DATE_TIME, timezone="Europe/London")

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

AWS Java SDK version used

2.25.23

JDK version used

21.0.1

Operating System and version

N/A

@chrisbloe-nhse chrisbloe-nhse added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 3, 2024
@chrisbloe-nhse chrisbloe-nhse changed the title DynamoDbAutoGeneratedTimestampAttribute date format and time zone DynamoDbAutoGeneratedTimestampAttribute custom date format and time zone Apr 3, 2024
@ungaratto93
Copy link

Hi, this feature can breaks who use a custom converter ?

@debora-ito
Copy link
Member

Hi @chrisbloe-nhse thank you for raising this, acknowledged as a feature request.

One possible workaround is to use attribute converters - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/ddb-en-client-adv-features-conversion.html

@ungaratto93 we'll keep custom attribute converters in mind when designing the feature, we avoid doing breaking changes in general.

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Apr 22, 2024
@debora-ito
Copy link
Member

@chrisbloe-nhse looks like this is already supported by using @DynamoDbConvertedBy together with @DynamoDbAutoGeneratedTimestampAttribute - see Use Cases 2 and 3 here: #2757.

For a code example, you can refer to the converters written for our internal tests: TimeFormatUpdateTestConverter.java, EpochMillisFormatTestConverter.java.

Let me know if this helps.

@debora-ito debora-ito added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label May 1, 2024
@debora-ito debora-ito self-assigned this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb-enhanced feature-request A feature should be added or improved. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

3 participants