Skip to content

Auto-configure java.time.Clock #31397

@JanecekPetr

Description

@JanecekPetr

Consider autoconfiguring a default java.time.Clock instance.

I was very surprised to see that there is currently is no autoconfigured Clock instance. I know it's only four lines of code in our application, and yet - every modern application will have them, and therefore Spring Boot can come in rescue:

@Bean
public Clock clock() {
    return Clock.systemDefaultZone();
}

I suppose this was not done because there may be people who want Clock.systemUTC() instead? Indeed, I see that, but with the exception of JEP 400 the JDK is very consistent in using the default timezone/locale etc., e.g. in ZonedDateTime.now() and all its friends.

I strongly believe the above autoconfiguration would positively please and spoil developers without taking risks. It's a small convenience, that's it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions