Skip to content

Commit

Permalink
fix datatype datetime,date,time
Browse files Browse the repository at this point in the history
  • Loading branch information
miftahurrahmi committed Nov 21, 2023
1 parent 6205cfc commit f4252ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
32 changes: 22 additions & 10 deletions src/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,31 @@ public function getContentByType($data_type, $data_row, $value)
$return_value = $value;
break;
case 'time':
$z_removed = explode('.', $value)[0];
$time = explode('T', $z_removed)[1];
$return_value = $time;
if($value == null){
$return_value = $value;
}else{
$z_removed = explode('.', $value)[0];
$time = explode('T', $z_removed)[1];
$return_value = $time;
}
break;
case 'date':
$z_removed = explode('.', $value)[0];
$date = explode('T', $z_removed)[0];
$return_value = $date;
if ($value == null) {
$return_value = $value;
} else{
$z_removed = explode('.', $value)[0];
$date = explode('T', $z_removed)[0];
$return_value = $date;
}
break;
case 'datetime':
$z_removed = explode('.', $value)[0];
$date_time = str_replace('T', ' ', $z_removed);
$return_value = $date_time;
if ($value == null) {
$return_value = $value;
} else{
$z_removed = explode('.', $value)[0];
$date_time = str_replace('T', ' ', $z_removed);
$return_value = $date_time;
}
break;
case 'select':
$return_value = $value;
Expand Down Expand Up @@ -569,7 +581,7 @@ public function updateData($data, $data_type)
}

if (in_array($data_row->type, [
'number',
'number', 'datetime', 'date', 'time',
])) {
$new_data[$key] = $this->getContentByType($data_type, $data_row, $value) !== null ? $this->getContentByType($data_type, $data_row, $value) : null;
} else {
Expand Down
16 changes: 12 additions & 4 deletions src/resources/badaso/pages/crud-generated/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,23 @@ export default {
data.value = parseInt(
this.record[this.$caseConvert.stringSnakeToCamel(data.field)]
);
} else if (data.type == "datetime" || data.type == "date") {
const dateValue = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
} else if(data.type == "datetime"){
data.value = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
]
? this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
].replace(" ", "T")
: null;
} else if(data.type == "date"){
var val = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
]
? this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
].replace(" ", "T")
: null;
data.value = new Date(dateValue);
data.value = val !== null ? new Date(val) : val;
} else if (data.value == undefined && data.type == "hidden") {
data.value = data.details.value ? data.details.value : "";
} else if (
Expand Down

0 comments on commit f4252ed

Please sign in to comment.