Skip to content

Commit e1708c6

Browse files
committed
truncate dropoff and pickup times
1 parent 7baea47 commit e1708c6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rule:
2+
kind: "import_header"
3+
regex: "OperationParams"
4+
pattern: "$HEADER"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rule:
2+
kind: value_argument
3+
nthChild: 2
4+
inside:
5+
kind: call_suffix
6+
stopBy: end
7+
has:
8+
any:
9+
- kind: value_arguments
10+
regex: pickupTime
11+
- kind: value_arguments
12+
regex: dropOffTime
13+
inside:
14+
kind: function_declaration
15+
stopBy: end
16+
regex: getQueryParams

customizations/generator/openapi/src/main/resources/post-processor/src/processors/get-cars-listings-operation-params-processor.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class GetCarsListingsOperationParamsProcessor extends Processor {
1111
this.rules = [
1212
this.changeClassParamType,
1313
this.changeBuilderMethodParamType,
14+
this.importChronoUnit,
15+
this.truncatePickupDropoffTimes,
1416
].map(rule => rule.bind(this));
1517
}
1618

@@ -29,4 +31,24 @@ export class GetCarsListingsOperationParamsProcessor extends Processor {
2931
return node.replace('java.time.LocalDateTime');
3032
});
3133
}
34+
35+
importChronoUnit(root: SgNode): Edit[] {
36+
const config = this.readRule('import-chrono-unit');
37+
38+
return root.findAll(config).map(node => {
39+
const room = 'import java.time.temporal.ChronoUnit';
40+
const header = node.getMatch('HEADER')?.text();
41+
42+
return node.replace(`${room}\n${header}`);
43+
});
44+
45+
}
46+
47+
truncatePickupDropoffTimes(root: SgNode): Edit[] {
48+
const config = this.readRule('truncate-pickup-dropoff-times');
49+
50+
return root.findAll(config).map(node => {
51+
return node.replace('it.truncatedTo(ChronoUnit.MINUTES).toString()');
52+
});
53+
}
3254
}

0 commit comments

Comments
 (0)