-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a77eda7
commit 717e6db
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
thirdeye-persistence/src/test/java/ai/startree/thirdeye/aspect/LocalDateAspect.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,40 @@ | ||
/* | ||
* Copyright 2024 StarTree Inc | ||
* | ||
* Licensed under the StarTree Community License (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.startree.ai/legal/startree-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OF ANY KIND, | ||
* either express or implied. | ||
* See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package ai.startree.thirdeye.aspect; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
|
||
@Aspect | ||
public class LocalDateAspect { | ||
|
||
@Pointcut("call(public static java.time.LocalDate java.time.LocalDate.now(..))") | ||
void localDateNow() { | ||
} | ||
|
||
@Around("localDateNow()") | ||
public Object aroundLocalDateNow(ProceedingJoinPoint pjp) throws Throwable { | ||
if (TimeProvider.instance().isTimedMocked()) { | ||
// assume localDate now is always called in a UTC context | ||
return LocalDate.ofInstant(Instant.ofEpochMilli(TimeProvider.instance().currentTimeMillis()), | ||
ZoneId.of("UTC")); | ||
} | ||
return pjp.proceed(); | ||
} | ||
} |
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