Skip to content

Commit

Permalink
Merge pull request #79 from AmandoVledder/immutable-datetime
Browse files Browse the repository at this point in the history
Support immutable date/datetime
  • Loading branch information
tcampbPPU authored Oct 30, 2024
2 parents ececd20 + 7ed370c commit c6a59a6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
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

0 comments on commit c6a59a6

Please sign in to comment.