From 80760a9a1e9975b30f4c5d3b142bf4f35c0c4fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pluchino?= Date: Sun, 12 Feb 2017 16:32:28 +0100 Subject: [PATCH] Make it compatible with date version --- Converter/SemverConverter.php | 1 + Converter/SemverUtil.php | 14 ++++++++++++++ Resources/doc/schema.md | 3 +++ Tests/Converter/SemverConverterTest.php | 3 +++ 4 files changed, 21 insertions(+) diff --git a/Converter/SemverConverter.php b/Converter/SemverConverter.php index e9319aa6..ca4fb41e 100644 --- a/Converter/SemverConverter.php +++ b/Converter/SemverConverter.php @@ -31,6 +31,7 @@ public function convertVersion($version) $prefix = preg_match('/^[a-z]/', $version) ? substr($version, 0, 1) : ''; $version = substr($version, strlen($prefix)); $version = SemverUtil::convertVersionMetadata($version); + $version = SemverUtil::convertDateVersion($version); return $prefix.$version; } diff --git a/Converter/SemverUtil.php b/Converter/SemverUtil.php index 34320e3f..8c68fade 100644 --- a/Converter/SemverUtil.php +++ b/Converter/SemverUtil.php @@ -35,6 +35,20 @@ public static function replaceAlias($version, $type) return str_replace(array('x', '*'), $value, $version); } + /** + * Converts the date or datetime version. + * + * @param string $version Tje version + * + * @return string + */ + public static function convertDateVersion($version) + { + return preg_match('/^\d{7,}\./', $version) + ? substr($version, 0, strpos($version, '.')).'.000000' + : $version; + } + /** * Converts the version metadata. * diff --git a/Resources/doc/schema.md b/Resources/doc/schema.md index 55b3cd06..6f995dcf 100644 --- a/Resources/doc/schema.md +++ b/Resources/doc/schema.md @@ -143,6 +143,9 @@ Here are the matches currently validated: | Semver version | Composer version | | ---------------- | ---------------- | | 1.2.3 | 1.2.3 | +| 20170124.0.0 | 20170124.000000 | +| 20170124.0 | 20170124.000000 | +| 20170124 | 20170124 | | 1.2.3alpha | 1.2.3-alpha1 | | 1.2.3-alpha | 1.2.3-alpha1 | | 1.2.3a | 1.2.3-alpha1 | diff --git a/Tests/Converter/SemverConverterTest.php b/Tests/Converter/SemverConverterTest.php index 44c46c15..efdd61bf 100644 --- a/Tests/Converter/SemverConverterTest.php +++ b/Tests/Converter/SemverConverterTest.php @@ -87,6 +87,9 @@ public function getTestVersions() array('1.2.3-build.2012', '1.2.3-patch.2012'), array('1.3.0–rc30.79', '1.3.0-RC30.79'), array('1.2.3-SNAPSHOT', '1.2.3-dev'), + array('20170124.0.0', '20170124.000000'), + array('20170124.0', '20170124.000000'), + array('20170124', '20170124'), array('latest', 'default || *'), array(null, '*'), array('', '*'),