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

Support immutable date/datetime #79

Merged
merged 3 commits into from
Oct 30, 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
3 changes: 3 additions & 0 deletions src/Actions/GetMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public function __invoke(bool $setTimestampsToDate = false): array

if ($setTimestampsToDate) {
$mappings['datetime'] = 'Date';
$mappings['immutable_datetime'] = 'Date';
$mappings['immutable_custom_datetime'] = 'Date';
$mappings['date'] = 'Date';
$mappings['immutable_date'] = 'Date';
$mappings['timestamp'] = 'Date';
}

Expand Down
3 changes: 3 additions & 0 deletions src/Constants/TypescriptMappings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class TypescriptMappings
'boolean' => 'boolean',
'collection' => 'Record<string, unknown>',
'date' => 'string',
'immutable_date' => 'string',
'datetime' => 'string',
'immutable_datetime' => 'string',
'immutable_custom_datetime' => 'string',
'decimal' => 'number',
'double' => 'number',
'encrypted' => 'string',
Expand Down
6 changes: 6 additions & 0 deletions test/Tests/Feature/Actions/GetMappingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ public function testActionCanSetTimestampsAsDate()
$mappings = $action(setTimestampsToDate: true);

$this->assertArrayHasKey('date', $mappings);
$this->assertArrayHasKey('immutable_date', $mappings);
$this->assertArrayHasKey('datetime', $mappings);
$this->assertArrayHasKey('immutable_datetime', $mappings);
$this->assertArrayHasKey('immutable_custom_datetime', $mappings);
$this->assertArrayHasKey('timestamp', $mappings);

$this->assertEquals('Date', $mappings['date']);
$this->assertEquals('Date', $mappings['immutable_date']);
$this->assertEquals('Date', $mappings['datetime']);
$this->assertEquals('Date', $mappings['immutable_datetime']);
$this->assertEquals('Date', $mappings['immutable_custom_datetime']);
$this->assertEquals('Date', $mappings['timestamp']);
}

Expand Down
3 changes: 3 additions & 0 deletions test/input/expectations/complex-model-with-cast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export interface Complex {
boolean: boolean
char: string
date_time: string
immutable_date_time: string
immutable_custom_date_time: string
date: string
immutable_date: string
decimal: number
double: number
enum: string
Expand Down
3 changes: 3 additions & 0 deletions test/input/expectations/complex-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export interface Complex {
boolean: boolean
char: string
date_time: string
immutable_date_time: string
immutable_custom_date_time: string
date: string
immutable_date: string
decimal: number
double: number
enum: string
Expand Down
3 changes: 3 additions & 0 deletions test/laravel-skeleton/app/Models/Complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ class Complex extends Model
'jsonb' => 'json',
'year' => 'int',
'casted_uppercase_string' => UpperCast::class,
'immutableDateTime' => 'immutable_date',
'immutableDate' => 'immutable_datetime',
'immutableCustomDateTime' => 'immutable_custom_datetime',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public function up(): void
$table->boolean('boolean');
$table->char('char');
$table->dateTime('dateTime');
$table->dateTime('immutableDateTime');
$table->dateTime('immutableCustomDateTime');
$table->date('date');
$table->date('immutable_date');
$table->decimal('decimal');
$table->double('double');
$table->enum('enum', [1, 2, 3, 'A', 'B']);
Expand Down