fileUtils->getNode($file); if (!$node) { if ($noCreate || is_numeric($file)) { $output->writeln("$file doesn't exist"); return ExitCode::Failure; } $node = $this->rootFolder->newFile($file); } if ($date) { $mtime = $this->parseDateOption($date); if (!$mtime) { $output->writeln("Invalid date format '$date'. Acceptable formats are: ISO8601, \"YYYY-MM-DD\" and Unix time in seconds."); } } else { $mtime = $this->clock->now(); } $node->touch($mtime->getTimestamp()); return ExitCode::Success; } /** * @return \DateTimeImmutable|false */ protected function parseDateOption(string $input) { // Handle Unix timestamp if (filter_var($input, FILTER_VALIDATE_INT)) { return new DateTimeImmutable('@' . $input); } // ISO8601 $date = DateTimeImmutable::createFromFormat(DateTimeImmutable::ATOM, $input); if ($date) { return $date; } // With fractions $date = DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $input); if ($date) { return $date; } // YYYY-MM-DD return DateTimeImmutable::createFromFormat('!Y-m-d', $input); } }