-
Notifications
You must be signed in to change notification settings - Fork 208
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
Showing
6 changed files
with
158 additions
and
42 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
84 changes: 84 additions & 0 deletions
84
src/main/java/com/rebuild/core/service/trigger/aviator/OverOperatorType.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,84 @@ | ||
/*! | ||
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved. | ||
rebuild is dual-licensed under commercial and open source licenses (GPLv3). | ||
See LICENSE and COMMERCIAL in the project root for license information. | ||
*/ | ||
|
||
package com.rebuild.core.service.trigger.aviator; | ||
|
||
import cn.devezhao.commons.CalendarUtils; | ||
import com.googlecode.aviator.lexer.token.OperatorType; | ||
import com.googlecode.aviator.runtime.function.AbstractFunction; | ||
import com.googlecode.aviator.runtime.type.AviatorLong; | ||
import com.googlecode.aviator.runtime.type.AviatorObject; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
/** | ||
* 操作符重载 | ||
* | ||
* @author RB | ||
* @since 2023/12/6 | ||
*/ | ||
public class OverOperatorType { | ||
|
||
private OverOperatorType() {} | ||
|
||
/** | ||
* 日期加 | ||
*/ | ||
static class DateAdd extends AbstractFunction { | ||
@Override | ||
public String getName() { | ||
return OperatorType.ADD.getToken(); | ||
} | ||
|
||
@Override | ||
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) { | ||
Object $argv1 = arg1.getValue(env); | ||
Object $argv2 = arg2.getValue(env); | ||
|
||
if ($argv1 instanceof Date && $argv2 instanceof Number) { | ||
return opDate((Date) $argv1, ((Number) $argv2).intValue()); | ||
} else if ($argv2 instanceof Date && $argv1 instanceof Number) { | ||
return opDate((Date) $argv2, ((Number) $argv1).intValue()); | ||
} else { | ||
return arg1.add(arg2, env); // Use default | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 日期减 | ||
*/ | ||
static class DateSub extends AbstractFunction { | ||
@Override | ||
public String getName() { | ||
return OperatorType.SUB.getToken(); | ||
} | ||
|
||
@Override | ||
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) { | ||
Object $argv1 = arg1.getValue(env); | ||
Object $argv2 = arg2.getValue(env); | ||
|
||
if ($argv1 instanceof Date && $argv2 instanceof Number) { | ||
return opDate((Date) $argv1, -((Number) $argv2).intValue()); | ||
} else if ($argv2 instanceof Date && $argv1 instanceof Number) { | ||
return opDate((Date) $argv2, -((Number) $argv1).intValue()); | ||
} else if ($argv1 instanceof Date && $argv2 instanceof Date) { | ||
int diff = CalendarUtils.getDayLeft((Date) $argv1, (Date) $argv2); | ||
return AviatorLong.valueOf(diff); | ||
} else { | ||
return arg1.add(arg2, env); // Use default | ||
} | ||
} | ||
} | ||
|
||
static AviatorDate opDate(Date date, int num) { | ||
Date d = CalendarUtils.addDay(date, num); | ||
return new AviatorDate(d); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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