Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple way to create a TimeValue object from a php DateTime object #102

Open
addshore opened this issue Dec 28, 2015 · 2 comments
Open

Comments

@addshore
Copy link
Contributor

No description provided.

@thiemowmde
Copy link
Contributor

A static TimeValue::newFromDateTime( DateTime $dateTime )?

@thiemowmde
Copy link
Contributor

I started playing around with this and I think this needs a parser. The biggest issues are:

  • What precision do you expect when providing a DateTime with the time set to "00:00:00"? Is this midnight? Or do you want the precision set to day?
  • What calendar model do you expect when providing a date in 1800?

When both int $precision and string $calendarModel parameters are required and not auto-detected from the provided DateTime $dateTime, the code you want is simple:

$value = new TimeValue(
    $dateTime->format( '+Y-m-d\TH:i:s\Z' ),
    0, 0, 0,
    $precision,
    $calendarModel
)

If you want auto-detection, you can use the existing IsoTimestampParser:

$parser = new IsoTimestampParser();
$value = $parser->parse( $dateTime->format( 'Y-m-d\TH:i:s' ) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants