Skip to content

Commit 173be23

Browse files
committed
TS declarations for temporal types
1 parent ceeec83 commit 173be23

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

test/types/v1/temporal-types.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (c) 2002-2018 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import {
21+
CypherDate,
22+
CypherDateTimeWithZoneOffset,
23+
CypherDuration,
24+
CypherLocalDateTime,
25+
CypherLocalTime,
26+
CypherTime,
27+
isCypherDate,
28+
isCypherDateTimeWithZoneId,
29+
isCypherDateTimeWithZoneOffset,
30+
isCypherDuration,
31+
isCypherLocalDateTime,
32+
isCypherLocalTime,
33+
isCypherTime
34+
} from "../../../types/v1/temporal-types";
35+
import Integer, {int} from "../../../types/v1/integer";
36+
37+
const duration1: CypherDuration = new CypherDuration(int(1), int(1), int(1), int(1));
38+
const months1: Integer = duration1.months;
39+
const days1: Integer = duration1.days;
40+
const seconds1: Integer = duration1.seconds;
41+
const nanoseconds1: Integer = duration1.nanoseconds;
42+
43+
const duration2: CypherDuration<number> = new CypherDuration(1, 1, 1, 1);
44+
const months2: number = duration2.months;
45+
const days2: number = duration2.days;
46+
const seconds2: number = duration2.seconds;
47+
const nanoseconds2: number = duration2.nanoseconds;
48+
49+
const localTime1: CypherLocalTime = new CypherLocalTime(int(1), int(1), int(1), int(1));
50+
const localTime1Hour1: Integer = localTime1.hour;
51+
const localTime1Minute1: Integer = localTime1.minute;
52+
const localTime1Second1: Integer = localTime1.second;
53+
const localTime1Nanosecond1: Integer = localTime1.nanosecond;
54+
55+
const localTime2: CypherLocalTime<number> = new CypherLocalTime(1, 1, 1, 1);
56+
const localTime2Hour1: number = localTime2.hour;
57+
const localTime2Minute1: number = localTime2.minute;
58+
const localTime2Second1: number = localTime2.second;
59+
const localTime2Nanosecond1: number = localTime2.nanosecond;
60+
61+
const time1: CypherTime = new CypherTime(localTime1, int(1));
62+
const localTime3: CypherLocalTime = time1.localTime;
63+
const offset1: Integer = time1.offsetSeconds;
64+
65+
const time2: CypherTime<number> = new CypherTime(localTime2, 1);
66+
const localTime4: CypherLocalTime<number> = time2.localTime;
67+
const offset2: number = time2.offsetSeconds;
68+
69+
const date1: CypherDate = new CypherDate(int(1), int(1), int(1));
70+
const date1Year1: Integer = date1.year;
71+
const date1Month1: Integer = date1.month;
72+
const date1Day1: Integer = date1.day;
73+
74+
const date2: CypherDate<number> = new CypherDate(1, 1, 1);
75+
const date2Year1: number = date2.year;
76+
const date2Month1: number = date2.month;
77+
const date2Day1: number = date2.day;
78+
79+
const localDateTime1: CypherLocalDateTime = new CypherLocalDateTime(date1, localTime1);
80+
const date3: CypherDate = localDateTime1.localDate;
81+
const localTime5: CypherLocalTime = localDateTime1.localTime;
82+
83+
const localDateTime2: CypherLocalDateTime<number> = new CypherLocalDateTime(date2, localTime2);
84+
const date4: CypherDate<number> = localDateTime2.localDate;
85+
const localTime6: CypherLocalTime<number> = localDateTime2.localTime;
86+
87+
const dateTime1: CypherDateTimeWithZoneOffset = new CypherDateTimeWithZoneOffset(localDateTime1, int(1));
88+
const localDateTime3: CypherLocalDateTime = dateTime1.localDateTime;
89+
const offset3: Integer = dateTime1.offsetSeconds;
90+
91+
const dateTime2: CypherDateTimeWithZoneOffset<number> = new CypherDateTimeWithZoneOffset(localDateTime2, 1);
92+
const localDateTime4: CypherLocalDateTime<number> = dateTime2.localDateTime;
93+
const offset4: number = dateTime2.offsetSeconds;
94+
95+
const isDuration: boolean = isCypherDuration(duration1);
96+
const isLocalTime: boolean = isCypherLocalTime(localTime1);
97+
const isTime: boolean = isCypherTime(time1);
98+
const isDate: boolean = isCypherDate(date1);
99+
const isLocalDateTime: boolean = isCypherLocalDateTime(localDateTime1);
100+
const isDateTimeWithZoneOffset: boolean = isCypherDateTimeWithZoneOffset(dateTime1);
101+
const isDateTimeWithZoneId: boolean = isCypherDateTimeWithZoneId(dateTime2);

types/v1/temporal-types.d.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* Copyright (c) 2002-2018 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import {NumberOrInteger} from './graph-types';
21+
import Integer from "./integer";
22+
23+
declare class CypherDuration<T extends NumberOrInteger = Integer> {
24+
months: T;
25+
days: T;
26+
seconds: T;
27+
nanoseconds: T;
28+
29+
constructor(months: T, days: T, seconds: T, nanoseconds: T)
30+
}
31+
32+
declare class CypherLocalTime<T extends NumberOrInteger = Integer> {
33+
hour: T;
34+
minute: T;
35+
second: T;
36+
nanosecond: T;
37+
38+
constructor(hour: T, minute: T, second: T, nanosecond: T);
39+
}
40+
41+
declare class CypherTime<T extends NumberOrInteger = Integer> {
42+
43+
localTime: CypherLocalTime<T>;
44+
offsetSeconds: T;
45+
46+
constructor(localTime: CypherLocalTime<T>, offsetSeconds: T);
47+
}
48+
49+
declare class CypherDate<T extends NumberOrInteger = Integer> {
50+
51+
year: T;
52+
month: T;
53+
day: T;
54+
55+
constructor(year: T, month: T, day: T);
56+
}
57+
58+
declare class CypherLocalDateTime<T extends NumberOrInteger = Integer> {
59+
60+
localDate: CypherDate<T>;
61+
localTime: CypherLocalTime<T>;
62+
63+
constructor(localDate: CypherDate<T>, localTime: CypherLocalTime<T>);
64+
}
65+
66+
declare class CypherDateTimeWithZoneOffset<T extends NumberOrInteger = Integer> {
67+
68+
localDateTime: CypherLocalDateTime<T>;
69+
offsetSeconds: T;
70+
71+
constructor(localDateTime: CypherLocalDateTime<T>, offsetSeconds: T);
72+
}
73+
74+
declare class CypherDateTimeWithZoneId<T extends NumberOrInteger = Integer> {
75+
76+
localDateTime: CypherLocalDateTime<T>;
77+
zoneId: string;
78+
79+
constructor(localDateTime: CypherLocalDateTime<T>, zoneId: string);
80+
}
81+
82+
declare function isCypherDuration(obj: object): boolean;
83+
84+
declare function isCypherLocalTime(obj: object): boolean;
85+
86+
declare function isCypherTime(obj: object): boolean;
87+
88+
declare function isCypherDate(obj: object): boolean;
89+
90+
declare function isCypherLocalDateTime(obj: object): boolean;
91+
92+
declare function isCypherDateTimeWithZoneOffset(obj: object): boolean;
93+
94+
declare function isCypherDateTimeWithZoneId(obj: object): boolean;
95+
96+
export {
97+
CypherDuration,
98+
CypherLocalTime,
99+
CypherTime,
100+
CypherDate,
101+
CypherLocalDateTime,
102+
CypherDateTimeWithZoneOffset,
103+
CypherDateTimeWithZoneId,
104+
isCypherDuration,
105+
isCypherLocalTime,
106+
isCypherTime,
107+
isCypherDate,
108+
isCypherLocalDateTime,
109+
isCypherDateTimeWithZoneOffset,
110+
isCypherDateTimeWithZoneId
111+
}

0 commit comments

Comments
 (0)