Skip to content

metadata: support setting Image.CreatedAt without using context #8322

@AkihiroSuda

Description

@AkihiroSuda

What is the problem you're trying to solve

// The value of `image.CreatedAt` passed from the caller is discarded here.
// Ideally we should return an error when the value is already set.
// However, as `image.CreatedAt` is defined as a non-pointer `time.Time`, we can't compare it to nil.
// And we can't compare it to `time.Time{}` either, as `time.Time{}` is a proper timestamp (1970-01-01 00:00:00).
if tm := epoch.FromContext(ctx); tm != nil {
image.CreatedAt = tm.UTC()
} else {
image.CreatedAt = time.Now().UTC()
}
image.UpdatedAt = image.CreatedAt

Currently, Create(ctx, img) does not consume img.CreatedAt value by design.

This issue can be currently worked around by ctx = epoch.WithSourceDateEpoch(ctx, customCreatedAt), but this should be possible without depending on ctx too.

Describe the solution you'd like

Consume the value of img.CreatedAt when it is explicitly set.

This change requires changing the type of CreatedAt form time.Time to *time.Time, or, add another property like CreatedAtIsSet, so as to differentiate "not set" from "1970-01-01 00:00:00".

Additional context

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions