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

Problem with \DateInterval object on insert/update #56

Closed
mdjimy opened this issue Mar 12, 2015 · 0 comments
Closed

Problem with \DateInterval object on insert/update #56

mdjimy opened this issue Mar 12, 2015 · 0 comments

Comments

@mdjimy
Copy link

mdjimy commented Mar 12, 2015

Hi,
I'm reacting on BC break in the issue nette/nette#1213.

The thing is, that it's really nice, that database layout returns the \DateInterval object (instead of \DateTime object) on select from time column, but in that case I'll expect, that database layout will also be able to work with \DateInterval object on insert/update or everywhere else, e.g.:

// Database layout can't process object \DateInterval so it tries to convert it into string
// An Exception in throw due to \DateInterval doesn't have implemented __toString method
$database->table("scheduler")->insert(array(..., "interval" => new \DateInterval("PT1H"), ...));

Or another example:

$activeRow = $database->table("scheduler")->where("id", 5)->fetch();
$interval = clone $activeRow->interval;
$interval->h++;
$activeRow->update(array("interval" => $interval)); // Same problem as above

There are two ways how to deal with this problem:

  1. Extend ISupplementalDriver interface by method formatInterval & fix method formatValue in class SqlPreprocessor to use it if value is instance of \DateInterval
  2. Create \Nette\Utils\DateInterval class (like \Nette\Utils\DateTime) which will extend class \DateInterval by function __toString & fix method normalizeRow in class ResultSet to use this new object instead of php \DateInterval

I prefer the first option, but it's up to you guys :)

If you don't have anything against this, I'd like to resolve this issue & create pull request. (Because this term at school I have a subject called Open-Source Programming in which I have to join some running open source project & resolve some issues.) :D

Thanks for your attention,
and I'll look forward to your reply.

@mdjimy mdjimy changed the title Problem with DateInterval on insert/update Problem with \DateInterval object on insert/update Mar 12, 2015
@dg dg closed this as completed in debd0f2 Mar 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant