Skip to content

[RFC] Support parsing Psl\DateTime\Duration from a string like P1Y1M1D #540

@rauanmayemir

Description

@rauanmayemir

Is your feature request related to a problem? Please describe.

PHP-native \DateInterval supports instantiating intervals from a duration string which is also perfectly aligned with standard XMLSchema's xs:duration format.

Describe the solution you'd like

/** @throws DateMalformedIntervalStringException */
$duration = Psl\DateTime\Duration::from('P1Y1M1D');

Describe alternatives you've considered

An alternative is either keep using \DateInterval or manually parsing which is error-prone anyway (Psl's highest granularity is 'hour', so it is on the user to convert years, months, days).

Metadata

Metadata

Assignees

Labels

Priority: MediumThis issue may be useful, and needs some attention.Status: In ProgressThis issue is being worked on, and has someone assigned.Type: EnhancementMost issues will probably ask for additions or changes.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions