2017 © Pedro Peláez
 

library date-interval

Adds DateInterval to Doctrine DBAL and ORM

image

doctrineum/date-interval

Adds DateInterval to Doctrine DBAL and ORM

  • Wednesday, July 18, 2018
  • by jaroslavtyc
  • Repository
  • 1 Watchers
  • 2 Stars
  • 4,221 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 17 Versions
  • 14 % Grown

The README.md

Doctrine DateInterval Type

Build Status Test Coverage License, (*1)

Adds DateInterval to Doctrine ORM (can be used as a @Column(type="date-interval")) and DBAL (can be used in DQL queries as DATE_INTERVAL)., (*2)

Usage

<?php
namespace ChopChop;

use Doctrine\ORM\Mapping as ORM;
use \Granam\DateInterval\DateInterval as GranamDateInterval;


/**
 * @ORM\Entity()
 */
class Job
{
    /**
     * @var int
     * @ORM\Id() @ORM\GeneratedValue(strategy="AUTO") @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var GranamDateInterval
     * @ORM\Column(type="date_interval")
     */
    private $interval;

    /**
     * @return GranamDateInterval
     */
    public function getInterval(): GranamDateInterval
    {
        return $this->interval;
    }

    /**
     * @param GranamDateInterval $interval
     */
    public function setInterval(GranamDateInterval $interval)
    {
        $this->interval = $interval;
    }
}

$annualJob = new Job();
$annualJob->setInterval(new GranamDateInterval('P1Y'));

$monthlyJob = new Job();
$monthlyJob->setInterval(new GranamDateInterval('P1M'));

$dailyJob = new Job();
$dailyJob->setInterval(new GranamDateInterval('P1D'));

/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager->persist($annualJob);
$entityManager->persist($monthlyJob);
$entityManager->persist($dailyJob);
$entityManager->flush();
$entityManager->clear();

/** @var Job[] $jobs */
$jobs = $entityManager->createQuery(
    "SELECT j FROM Jobs j WHERE j.interval < DATE_INTERVAL('P1Y') ORDER BY j.interval ASC"
)->getResult();

echo $jobs[0]->getInterval()->toSpec(); // "P1D";
echo $jobs[1]->getInterval()->toSpec(); // "P1M"
// note: to spec conversion is feature of HerreraDateInterval

Installation

Add it to your list of Composer dependencies (or by manual edit your composer.json, the require section), (*3)

composer require jaroslavtyc/doctrineum-date-interval

Register new DBAL type:, (*4)

<?php

use Doctrineum\DateInterval\DBAL\Types\DateIntervalType;

DateIntervalType::registerSelf();

Register new Doctrine ORM function:, (*5)

<?php

use Doctrineum\DateInterval\ORM\Query\AST\Functions\DateIntervalFunction;
// ... $entityManager = ...
/** @var \Doctrine\ORM\EntityManager $entityManager */
DateIntervalFunction::addSelfToDQL($entityManager);

When using Symfony with Doctrine you can do the same as above by configuration:, (*6)

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            date_interval: date_interval
        types:
            date_interval: Doctrineum\DateInterval\DBAL\Types\DateIntervalType
    orm:
        # ...
        dql:
            datetime_functions:
                DATE_INTERVAL: Doctrineum\DateInterval\ORM\Query\AST\Functions\DateIntervalFunction

The Versions

18/07 2018

dev-master

9999999-dev https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

18/07 2018

3.1.x-dev

3.1.9999999.9999999-dev https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

18/07 2018
19/02 2017

3.0.x-dev

3.0.9999999.9999999-dev https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

19/02 2017

3.0.1

3.0.1.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

19/02 2017

3.0.0

3.0.0.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

17/01 2017

2.0.0

2.0.0.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

17/01 2017

1.1.8

1.1.8.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

17/01 2017

1.1.7

1.1.7.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

11/08 2016

1.1.6

1.1.6.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

11/08 2016

1.1.5

1.1.5.0 https://github.com/jaroslavtyc/doctrineum-date-interval

Adds DateInterval to Doctrine DBAL and ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval dateinterval

06/03 2016

1.1.4

1.1.4.0 https://github.com/tubssz/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lemke

doctrine date interval

06/03 2016

1.1.2

1.1.2.0 https://github.com/tubssz/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lemke

doctrine date interval

06/03 2016

1.1.3

1.1.3.0 https://github.com/tubssz/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lemke

doctrine date interval

04/02 2016

1.1.1

1.1.1.0 https://github.com/tubssp/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lemke

doctrine date interval

04/02 2016

1.1.0

1.1.0.0 https://github.com/tubssp/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andreas Lemke

doctrine date interval

20/02 2013

1.0.0

1.0.0.0 http://herrera-io.github.com/php-doctrine-dateinterval

Supports DateInterval in Doctrine DBAL and ORM.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date interval