What Problem Does This Solve?

The duration format has a number of ways that it can be expressed, and this set of extensions should allow us to deal with all of them. It will be most useful integrated into an XML parser.
It will read a duration from a String instance, and return a DateComponents instance, representing the duration in that String.
You can also do the reverse, and take a DateComponents instance, and express it as a properly-formatted xsd:duration String.

Requirements

It should work fine for osx, tvOS and iOS. It only depends on the Swift Foundation library.

For our purposes, when a unit is not specified, we don’t include it at all in the DateComponents. If the unit is specified, but is a zero (0), then we specify that unit as zero in the DateComponents.

Examples

Not much to show, really. The parser is ridiculously easy to use.

Parsing From A String:

Each part is composed of 1 or more decimal digits, immediately succeeded by Y (years), M (months or minutes), D (days), H (hours), or S (seconds). Seconds can be expressed as a decimal. All other numbers are integers.

DEPENDENCIES

There are no dependencies to use RVS_ParseXMLDuration in your project. In order to test it and run it in the module project, you should use CocoaPods to install SwiftLint, although that is not required. It’s just good practice.

LICENSE

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.