-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAUSEWAY-3743: adds TimeZoneChoiceProvider SPI to customize zone choices
- for e.g. Wicket Viewer Login
- Loading branch information
1 parent
f872880
commit 64263ab
Showing
3 changed files
with
77 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...plib/src/main/java/org/apache/causeway/applib/value/semantics/TimeZoneChoiceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.causeway.applib.value.semantics; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.val; | ||
|
||
/** | ||
* When implemented by a service {@link #getAvailableZoneIds()} | ||
* can be customized to limit the time-zone choices | ||
* as e.g. offered by the <i>Wicket Viewer<i> login page. | ||
* | ||
* @since 2.1, 3.1 | ||
*/ | ||
public interface TimeZoneChoiceProvider { | ||
|
||
/** | ||
* For temporal value editing, provides the list of available time zones to choose from. | ||
*/ | ||
default List<ZoneId> getAvailableZoneIds() { | ||
return ZoneId.getAvailableZoneIds().stream() | ||
.sorted() | ||
.map(ZoneId::of) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* For temporal value editing, provides the list of available offsets to choose from. | ||
*/ | ||
default List<ZoneOffset> getAvailableOffsets() { | ||
val now = LocalDateTime.now(); | ||
return getAvailableZoneIds().stream() | ||
.map(ZoneId::getRules) | ||
.flatMap(zoneIdRules->zoneIdRules.getValidOffsets(now).stream()) | ||
.sorted() | ||
.distinct() | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Returns the fallback implementation, which provides all ZoneIds known to the JVM. | ||
*/ | ||
static TimeZoneChoiceProvider fallback() { | ||
return new TimeZoneChoiceProvider() {}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters