Skip to content

Commit

Permalink
Fix usage of timezone-fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
eigan committed Jul 5, 2020
1 parent 60b74dc commit e99ae02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function configure()
$this->addOption('dry-run', '', InputOption::VALUE_NONE, 'Do not move or link files');
$this->addOption('log-path', '', InputOption::VALUE_OPTIONAL, 'Path to where write logfile');
$this->addOption('ignore-checksum', '', InputOption::VALUE_NONE, 'Skip duplication check with checksum, use only size and date');
$this->addOption('timezone-fallback', '', InputOption::VALUE_NONE, 'Timezone when we are unable to retrieve the timezone from file.');
$this->addOption('timezone-fallback', '', InputOption::VALUE_OPTIONAL, 'Timezone when we are unable to retrieve the timezone from file.');
}

/**
Expand Down Expand Up @@ -213,7 +213,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fileDestinationPath = $this->formatDestinationPath($destination, $sourceFile, $format);
} catch (NoTimezoneDefinedException $e) {
$output->writeln("");
$output->writeln('<fg=red>Missing timezone</>');
$output->writeln("<fg=red>Missing timezone for {$e->getSourceFile()->getPath()}</>");
$output->writeln("The current file failed because a fallback timezone was not provided. Please provide your timezone with the --timezone-fallback option.");
$output->writeln("The file most likely store its date in UTC, and we wanted to convert to your local timezone.");
$output->writeln("See list of supported timezones here: https://www.php.net/manual/en/timezones.php.");
Expand Down
17 changes: 17 additions & 0 deletions src/Exception/NoTimezoneDefinedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

namespace Eigan\Mediasort\Exception;

use Eigan\Mediasort\File;
use RuntimeException;
use Throwable;

class NoTimezoneDefinedException extends RuntimeException
{
/**
* @var File
*/
private $sourceFile;

public function __construct(File $file)
{
parent::__construct("No timezone defined for {$file->getPath()}");

$this->sourceFile = $file;
}

public function getSourceFile(): File
{
return $this->sourceFile;
}
}
2 changes: 1 addition & 1 deletion src/FilenameFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private function parseId3Date(File $file)
}

if ($this->haveSetTimezone === false) {
throw new NoTimezoneDefinedException();
throw new NoTimezoneDefinedException($file);
}

$date = new \DateTime('@'.$subatom['creation_time_unix']);
Expand Down

0 comments on commit e99ae02

Please sign in to comment.