Skip to content

Commit

Permalink
Make it compatible with date version
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Feb 12, 2017
1 parent 69fd13c commit 80760a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions Tests/Converter/SemverConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('', '*'),
Expand Down

2 comments on commit 80760a9

@nazar-pc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Releases might have more non-zero digits after dot, for instance, there are such versions of google/closure-compiler-js:

  • 20160828.0.0
  • 20160828.0.1
  • 20160713.0.2

@francoispluchino
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Added by 41520c8.

Please sign in to comment.