Skip to content
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
23 changes: 8 additions & 15 deletions src/Phaseolies/Console/Schedule/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,14 @@ protected function choice(string $question, array $choices, $default = null)
protected function multipleChoice(string $question, array $choices, $default = null): array
{
$helper = $this->getHelper('question');
$question = new ChoiceQuestion("<question>{$question}</question>", $choices, $default);
$question = new ChoiceQuestion("<question>{$question}</question>", $choices);
$question->setMultiselect(true);
$question->setErrorMessage('Choice %s is invalid.');

// For multiselect, default as null
if ($default !== null) {
$question->setDefault($default);
}

return $helper->ask($this->input, $this->output, $question);
}
Expand All @@ -442,13 +447,7 @@ protected function multipleChoice(string $question, array $choices, $default = n
*/
protected function createProgressBar(int $max = 0)
{
$progressBar = $this->getHelper('progress');

if (!$progressBar) {
throw new \RuntimeException('Progress bar helper not found.');
}

return $progressBar->create($this->output, $max);
return new \Symfony\Component\Console\Helper\ProgressBar($this->output, $max);
}

/**
Expand All @@ -458,12 +457,6 @@ protected function createProgressBar(int $max = 0)
*/
protected function createTable()
{
$table = $this->getHelper('table');

if (!$table) {
throw new \RuntimeException('Table helper not found.');
}

return $table->setStyle('default');
return new \Symfony\Component\Console\Helper\Table($this->output);
}
}
25 changes: 0 additions & 25 deletions src/Phaseolies/Database/Eloquent/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,31 +436,6 @@ public function date(string $column): string
};
}

/**
* Format date for database comparison
*
* @param mixed $date
* @param bool $includeTime
* @return string
*/
public function formatDate($date, bool $includeTime = false): string
{
if ($date instanceof \DateTimeInterface) {
return $includeTime
? $date->format('Y-m-d H:i:s')
: $date->format('Y-m-d');
}

if (is_string($date)) {
if (!$includeTime && strlen($date) > 10) {
return substr($date, 0, 10);
}
return $date;
}

throw new \InvalidArgumentException('Invalid date provided');
}

/**
* Get the standard deviation function for the current database driver
*
Expand Down
60 changes: 46 additions & 14 deletions src/Phaseolies/Database/Eloquent/Query/InteractsWithTimeframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public function whereLastYear(string $column): self
*/
public function whereDateBetween(string $column, $start, $end): self
{
$start = $this->formatDate($start, false);
$end = $this->formatDate($end, false);
$start = $this->formatDate($start);
$end = $this->formatDate($end);

return $this->whereBetween($this->date($column), [$start, $end]);
}
Expand All @@ -328,30 +328,62 @@ public function whereDateBetween(string $column, $start, $end): self
*/
public function whereDateTimeBetween(string $column, $start, $end): self
{
$start = $this->formatDate($start, true);
$end = $this->formatDate($end, true);
$start = $this->formatDateTime($start, true);
$end = $this->formatDateTime($end, true);

return $this->whereBetween($column, [$start, $end]);
}

/**
* Add a where date between condition with time handling
* Format date for database comparison
*
* @param string $column
* @param mixed $start
* @param mixed $end
* @param bool $includeTime
* @return self
* @param mixed $date
* @return string
*/
public function whereDateBetweenLegacy(string $column, $start, $end, bool $includeTime = false): self
public function formatDate($date): string
{
if ($includeTime) {
return $this->whereDateTimeBetween($column, $start, $end);
if ($date instanceof \DateTimeInterface) {
return $date->format('Y-m-d');
}

if (is_string($date)) {
return substr($date, 0, 10);
}

return $this->whereDateBetween($column, $start, $end);
throw new \InvalidArgumentException('Invalid date provided');
}

/**
* Format datetime for database comparison with proper time handling
*
* @param mixed $date
* @param string $type 'start' or 'end' to indicate how to handle missing time
* @return string
*/
public function formatDateTime($date, string $type = 'start'): string
{
if ($date instanceof \DateTimeInterface) {
return $date->format('Y-m-d H:i:s');
}

if (is_string($date)) {
// If it's already a full datetime string, return as-is
if (strlen($date) > 10 && str_contains($date, ' ')) {
return $date;
}

// If it's just a date string, add appropriate time
if (strlen($date) === 10) {
return $type === 'start'
? $date . ' 00:00:00'
: $date . ' 23:59:59';
}

return $date;
}

throw new \InvalidArgumentException('Invalid date provided');
}

/**
* Get the proper operator for date range based on includeTime flag
Expand Down
Loading