Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added date helper functions #37

Merged
merged 8 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Use the following dependency in your code.
<dependency>
<groupId>io.appform.hope</groupId>
<artifactId>hope-lang</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</dependency>
```

Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.5
- A host of Date functions are now supported as built-in functions
- `date.now()`, `date.secondOfMinute()`, `date.minuteOfHour()`, `date.hourOfDay()`, `date.dayOfWeek()`, `date.dayOfMonth()`, `date.dayOfYear()`, `date.weekOfMonth()`, `date.weekOfYear()`, `date.monthOfYear()`, `date.year()`

# 2.0.4
- Bugfix: Removed the filterInputsBy package line, which prevents scanning custom packages that are registered on hopebuilder

Expand Down
2 changes: 1 addition & 1 deletion dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
io.appform.hope:hope:pom:2.0.4
io.appform.hope:hope:pom:2.0.5
+- org.openjdk.jmh:jmh-core:jar:1.35:test
| +- net.sf.jopt-simple:jopt-simple:jar:5.0.4:test
| \- org.apache.commons:commons-math3:jar:3.2:test
Expand Down
2 changes: 1 addition & 1 deletion hope-core/dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
io.appform.hope:hope-core:jar:2.0.4
io.appform.hope:hope-core:jar:2.0.5
+- org.reflections:reflections:jar:0.9.12:compile
| \- org.javassist:javassist:jar:3.26.0-GA:compile
+- org.openjdk.jmh:jmh-core:jar:1.35:test
Expand Down
2 changes: 1 addition & 1 deletion hope-core/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>hope</artifactId>
<groupId>io.appform.hope</groupId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hope-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion hope-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hope</artifactId>
<groupId>io.appform.hope</groupId>
<version>2.0.4</version>
<version>2.0.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* returns the current day of the month as a NumericValue.
*/
@FunctionImplementation("date.day_of_month")
public class DayOfMonth extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getDayOfMonth());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* returns the current day of the week as a NumericValue.
*/
@FunctionImplementation("date.day_of_week")
public class DayOfWeek extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getDayOfWeek().getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* returns the current day of the year as a NumericValue.
*/
@FunctionImplementation("date.day_of_year")
public class DayOfYear extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getDayOfYear());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* Returns the current hour of the day as a NumericValue.
*/
@FunctionImplementation("date.hour_of_day")
public class HourOfDay extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getHour());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* Returns the current minute of the hour as a NumericValue.
*/
@FunctionImplementation("date.minute_of_hour")
public class MinuteOfHour extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getMinute());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;
import java.time.temporal.WeekFields;
import java.util.Locale;

/**
* returns the current month of the year as a NumericValue.
*/
@FunctionImplementation("date.month_of_year")
public class MonthOfYear extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getMonth().getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

/**
* Returns current UNIX epoch time {@link NumericValue} in milliseconds.
*/
@FunctionImplementation("date.now")
public class Now extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(System.currentTimeMillis());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;

/**
* Returns the current second of the minute as a NumericValue.
*/
@FunctionImplementation("date.second_of_minute")
public class SecondOfMinute extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().getSecond());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;
import java.time.temporal.WeekFields;
import java.util.Locale;

/**
* returns the current week of the month as a NumericValue.
*/
@FunctionImplementation("date.week_of_month")
public class WeekOfMonth extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().get(WeekFields.of(Locale.getDefault()).weekOfMonth()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019. Santanu Sinha
*
* Licensed 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 io.appform.hope.core.functions.impl.date;

import io.appform.hope.core.functions.FunctionImplementation;
import io.appform.hope.core.functions.HopeFunction;
import io.appform.hope.core.values.NumericValue;
import io.appform.hope.core.visitors.Evaluator;

import java.time.LocalDateTime;
import java.time.temporal.WeekFields;
import java.util.Locale;

/**
* returns the current week of the year as a NumericValue.
*/
@FunctionImplementation("date.week_of_year")
public class WeekOfYear extends HopeFunction<NumericValue> {
@Override
public NumericValue apply(Evaluator.EvaluationContext evaluationContext) {
return new NumericValue(LocalDateTime.now().get(WeekFields.of(Locale.getDefault()).weekOfYear()));
}
}
Loading