-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce all remaining temporal functions
Also a slight simpligying refactoring to StructureBuilder.
- Loading branch information
Showing
21 changed files
with
682 additions
and
105 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
community/kernel/src/main/java/org/neo4j/kernel/impl/proc/temporal/DateFunction.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,80 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.proc.temporal; | ||
|
||
import java.time.Clock; | ||
import java.time.ZoneId; | ||
import java.time.temporal.TemporalUnit; | ||
import java.util.function.Supplier; | ||
|
||
import org.neo4j.procedure.Description; | ||
import org.neo4j.values.AnyValue; | ||
import org.neo4j.values.storable.DateValue; | ||
import org.neo4j.values.storable.TemporalValue; | ||
import org.neo4j.values.storable.TextValue; | ||
import org.neo4j.values.virtual.MapValue; | ||
|
||
import static org.neo4j.kernel.api.proc.Neo4jTypes.NTDate; | ||
|
||
@Description( "Create a Date instant." ) | ||
class DateFunction extends TemporalFunction<DateValue> | ||
{ | ||
DateFunction() | ||
{ | ||
super( NTDate ); | ||
} | ||
|
||
@Override | ||
protected DateValue now( Clock clock, String timezone ) | ||
{ | ||
return timezone == null ? DateValue.now( clock ) : DateValue.now( clock, timezone ); | ||
} | ||
|
||
@Override | ||
protected DateValue parse( TextValue value, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return DateValue.parse( value ); | ||
} | ||
|
||
@Override | ||
protected DateValue build( MapValue map, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return DateValue.build( map, defaultZone ); | ||
} | ||
|
||
@Override | ||
protected DateValue positionalCreate( AnyValue[] input ) | ||
{ | ||
if ( input.length != 3 ) | ||
{ | ||
throw new IllegalArgumentException( "expected 3 arguments" ); | ||
} | ||
return DateValue.date( | ||
anInt( "year", input[0] ), | ||
anInt( "month", input[1] ), | ||
anInt( "day", input[2] ) ); | ||
} | ||
|
||
@Override | ||
protected DateValue truncate( TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return DateValue.truncate( unit, input, fields, defaultZone ); | ||
} | ||
} |
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
84 changes: 84 additions & 0 deletions
84
...unity/kernel/src/main/java/org/neo4j/kernel/impl/proc/temporal/LocalDateTimeFunction.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) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.proc.temporal; | ||
|
||
import java.time.Clock; | ||
import java.time.ZoneId; | ||
import java.time.temporal.TemporalUnit; | ||
import java.util.function.Supplier; | ||
|
||
import org.neo4j.procedure.Description; | ||
import org.neo4j.values.AnyValue; | ||
import org.neo4j.values.storable.LocalDateTimeValue; | ||
import org.neo4j.values.storable.TemporalValue; | ||
import org.neo4j.values.storable.TextValue; | ||
import org.neo4j.values.virtual.MapValue; | ||
|
||
import static org.neo4j.kernel.api.proc.Neo4jTypes.NTLocalDateTime; | ||
|
||
@Description( "Create a LocalDateTime instant." ) | ||
class LocalDateTimeFunction extends TemporalFunction<LocalDateTimeValue> | ||
{ | ||
LocalDateTimeFunction() | ||
{ | ||
super( NTLocalDateTime ); | ||
} | ||
|
||
@Override | ||
protected LocalDateTimeValue now( Clock clock, String timezone ) | ||
{ | ||
return timezone == null ? LocalDateTimeValue.now( clock ) : LocalDateTimeValue.now( clock, timezone ); | ||
} | ||
|
||
@Override | ||
protected LocalDateTimeValue parse( TextValue value, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalDateTimeValue.parse( value ); | ||
} | ||
|
||
@Override | ||
protected LocalDateTimeValue build( MapValue map, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalDateTimeValue.build( map, defaultZone ); | ||
} | ||
|
||
@Override | ||
protected LocalDateTimeValue positionalCreate( AnyValue[] input ) | ||
{ | ||
if ( input.length != 7 ) | ||
{ | ||
throw new IllegalArgumentException( "expected 7 arguments" ); | ||
} | ||
return LocalDateTimeValue.localDateTime( | ||
anInt( "year", input[0] ), | ||
anInt( "month", input[1] ), | ||
anInt( "day", input[2] ), | ||
anInt( "hour", input[3] ), | ||
anInt( "minute", input[4] ), | ||
anInt( "second", input[5] ), | ||
anInt( "nanos", input[6] ) ); | ||
} | ||
|
||
@Override | ||
protected LocalDateTimeValue truncate( TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalDateTimeValue.truncate( unit, input, fields, defaultZone ); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
community/kernel/src/main/java/org/neo4j/kernel/impl/proc/temporal/LocalTimeFunction.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,81 @@ | ||
/* | ||
* Copyright (c) 2002-2018 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.kernel.impl.proc.temporal; | ||
|
||
import java.time.Clock; | ||
import java.time.ZoneId; | ||
import java.time.temporal.TemporalUnit; | ||
import java.util.function.Supplier; | ||
|
||
import org.neo4j.procedure.Description; | ||
import org.neo4j.values.AnyValue; | ||
import org.neo4j.values.storable.TemporalValue; | ||
import org.neo4j.values.storable.TextValue; | ||
import org.neo4j.values.storable.LocalTimeValue; | ||
import org.neo4j.values.virtual.MapValue; | ||
|
||
import static org.neo4j.kernel.api.proc.Neo4jTypes.NTLocalTime; | ||
|
||
@Description( "Create a LocalTime instant." ) | ||
class LocalTimeFunction extends TemporalFunction<LocalTimeValue> | ||
{ | ||
LocalTimeFunction() | ||
{ | ||
super( NTLocalTime ); | ||
} | ||
|
||
@Override | ||
protected LocalTimeValue now( Clock clock, String timezone ) | ||
{ | ||
return timezone == null ? LocalTimeValue.now( clock ) : LocalTimeValue.now( clock, timezone ); | ||
} | ||
|
||
@Override | ||
protected LocalTimeValue parse( TextValue value, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalTimeValue.parse( value ); | ||
} | ||
|
||
@Override | ||
protected LocalTimeValue build( MapValue map, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalTimeValue.build( map, defaultZone ); | ||
} | ||
|
||
@Override | ||
protected LocalTimeValue positionalCreate( AnyValue[] input ) | ||
{ | ||
if ( input.length != 4 ) | ||
{ | ||
throw new IllegalArgumentException( "expected 4 arguments" ); | ||
} | ||
return LocalTimeValue.localTime( | ||
anInt( "hour", input[0] ), | ||
anInt( "minute", input[1] ), | ||
anInt( "second", input[2] ), | ||
anInt( "nanos", input[3] ) ); | ||
} | ||
|
||
@Override | ||
protected LocalTimeValue truncate( TemporalUnit unit, TemporalValue input, MapValue fields, Supplier<ZoneId> defaultZone ) | ||
{ | ||
return LocalTimeValue.truncate( unit, input, fields, defaultZone ); | ||
} | ||
} |
Oops, something went wrong.