Class DateRangeStrategy
java.lang.Object
cloud.opencode.base.feature.strategy.DateRangeStrategy
- All Implemented Interfaces:
EnableStrategy
Date Range Strategy
日期范围策略
Strategy that enables feature within a specific time window.
在特定时间窗口内启用功能的策略。
Features | 主要功能:
- Time-based activation - 基于时间的激活
- Scheduled features - 定时功能
- Limited-time promotions - 限时促销
Usage Examples | 使用示例:
// Spring sale (March 2024)
Feature feature = Feature.builder("spring-sale")
.strategy(new DateRangeStrategy(
Instant.parse("2024-03-01T00:00:00Z"),
Instant.parse("2024-03-31T23:59:59Z")
))
.build();
// Using LocalDateTime
Feature feature = Feature.builder("new-year-promo")
.strategy(DateRangeStrategy.of(
LocalDateTime.of(2024, 1, 1, 0, 0),
LocalDateTime.of(2024, 1, 7, 23, 59)
))
.build();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDateRangeStrategy(Instant startTime, Instant endTime) Create date range strategy 创建日期范围策略 -
Method Summary
Modifier and TypeMethodDescriptionstatic DateRangeStrategyCreate strategy that starts at specified time and never ends 创建从指定时间开始永不结束的策略Get end time 获取结束时间Get start time 获取开始时间booleanhasEnded()Check if the time window has ended 检查时间窗口是否已结束booleanCheck if the time window has started 检查时间窗口是否已开始booleanisEnabled(Feature feature, FeatureContext context) Check if current time is within the date range 检查当前时间是否在日期范围内static DateRangeStrategyof(LocalDateTime startTime, LocalDateTime endTime) Create from LocalDateTime using system timezone 使用系统时区从LocalDateTime创建static DateRangeStrategyof(LocalDateTime startTime, LocalDateTime endTime, ZoneId zoneId) Create from LocalDateTime with specific timezone 使用特定时区从LocalDateTime创建toString()static DateRangeStrategyCreate strategy that starts now and ends at specified time 创建从现在开始到指定时间结束的策略
-
Constructor Details
-
DateRangeStrategy
-
-
Method Details
-
of
Create from LocalDateTime using system timezone 使用系统时区从LocalDateTime创建- Parameters:
startTime- the start time | 开始时间endTime- the end time | 结束时间- Returns:
- new DateRangeStrategy | 新的DateRangeStrategy
-
of
Create from LocalDateTime with specific timezone 使用特定时区从LocalDateTime创建- Parameters:
startTime- the start time | 开始时间endTime- the end time | 结束时间zoneId- the timezone | 时区- Returns:
- new DateRangeStrategy | 新的DateRangeStrategy
-
until
Create strategy that starts now and ends at specified time 创建从现在开始到指定时间结束的策略- Parameters:
endTime- the end time | 结束时间- Returns:
- new DateRangeStrategy | 新的DateRangeStrategy
-
from
Create strategy that starts at specified time and never ends 创建从指定时间开始永不结束的策略- Parameters:
startTime- the start time | 开始时间- Returns:
- new DateRangeStrategy | 新的DateRangeStrategy
-
isEnabled
Check if current time is within the date range 检查当前时间是否在日期范围内- Specified by:
isEnabledin interfaceEnableStrategy- Parameters:
feature- the feature | 功能context- the context | 上下文- Returns:
- true if within range | 如果在范围内返回true
-
getStartTime
-
getEndTime
-
hasStarted
public boolean hasStarted()Check if the time window has started 检查时间窗口是否已开始- Returns:
- true if started | 如果已开始返回true
-
hasEnded
public boolean hasEnded()Check if the time window has ended 检查时间窗口是否已结束- Returns:
- true if ended | 如果已结束返回true
-
toString
-