Skip to content

Construction of DateTime object from relative time in database #1213

@miso-belica

Description

@miso-belica

Hi,
I have SQL table like this:

CREATE TABLE `events` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key.',
  `time_delta` time DEFAULT NULL COMMENT 'Relative time when event should be fired (e.g. 10 days before expiration).',
  `triggered` bit(1) NOT NULL DEFAULT b'0' COMMENT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

But when I try to fetch data from table selection, I get exception:

DateTime::__construct(): Failed to parse time string (-240:00:00) at position 4 (:): Unexpected character

I use time column like time interval but Nette try to store it like a DateTime object. I think DateInterval object is better representation of column of type time.

MySQL documentation says: "TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative)."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions