spring-modulith icon indicating copy to clipboard operation
spring-modulith copied to clipboard

Customizing the Event Publication Date, but not working

Open tlarbals824 opened this issue 1 year ago • 1 comments
trafficstars

When I configured a custom Clock class as a bean, the event's publish date was still displayed in UTC timezone. So, I looked for the point where the EventPublication instance was created, and I found it.

The publishDate and completionDate types of EventPublication are Instant. Therefore, if I change the clock bean, the instant will always be set to UTC timezone time.

public class DefaultEventPublicationRegistry implements DisposableBean, EventPublicationRegistry, CompletedEventPublications {

public Collection<TargetEventPublication> store(Object event, Stream<PublicationTargetIdentifier> listeners) {
        Stream var10000 = listeners.map((it) -> {
            return TargetEventPublication.of(event, it, this.clock.instant()); // makes an Instant instance, and it always uses UTC timezone
        }).peek((it) -> {
            LOGGER.debug("Registering publication of {} for {}.", it.getEvent().getClass().getName(), it.getTargetIdentifier().getValue());
        });
        ...
    }
}

How can I customize the event publication date?

tlarbals824 avatar Jun 25 '24 07:06 tlarbals824

The publishDate and completionDate types of EventPublication are Instant. Therefore, if I change the clock bean, the instant will always be set to UTC timezone time.

I cannot follow here. If you change the Clock instance (i.e. declare a custom bean of that type) it will use whatever that bean returns for that method. There is currently no way to customize the time to be used as publication date logically different than "now". What would be a good use case to do that in the context of the registry?

odrotbohm avatar Jun 25 '24 10:06 odrotbohm

Closing due to the lack of feedback.

odrotbohm avatar Sep 03 '24 06:09 odrotbohm