2017 © Pedro Peláez
 

library doctrine-daterange

Supports postgre DateRange in Doctrine DBAL.

image

salamek/doctrine-daterange

Supports postgre DateRange in Doctrine DBAL.

  • Thursday, June 23, 2016
  • by Salamek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,336 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 24 % Grown

The README.md

Doctrine DateRange Type

Build Status, (*1)

Supports PostgreSQL DateRange in Doctrine DBAL., (*2)

Summary

The DateRange library, (*3)

  • adds a daterange type to DBAL

Installation

Add it to your list of Composer dependencies:, (*4)

composer require salamek/doctrine-daterange

Register it with Doctrine DBAL:, (*5)

<?php

use Doctrine\DBAL\Types\Type;
use Salamek\Doctrine\DBAL\Types\DateRangeType;

Type::addType(
    DateRangeType::DATERANGE,
    'Salamek\\Doctrine\\DBAL\\Types\\DateRangeType'
);

When using Symfony2 with Doctrine you can do the same as above by only changing your configuration:, (*6)

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        # ...
        mapping_types:
            daterange: daterange
        types:
            daterange:  Salamek\Doctrine\DBAL\Types\DateRangeType

Usage

<?php

/**
 * @Entity()
 * @Table(name="jobs")
 */
class Job
{
    /**
     * @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     * @Id()
     */
    private $id;

    /**
     * @Column(type="daterange")
     */
    private $range;

    /**
     * @return \Salamek\DateRange
     */
    public function getRange()
    {
        return $this->range;
    }

    /**
     * @param \Salamek\DateRange $range
     */
    public function setRange(\Salamek\DateRange $range)
    {
        $this->range = $range;
    }
}

$annualJob = new Job();
$annualJob->setRange(new \Salamek\DateRange(new \DateTime, (new \DateTime)->modify('+1 year')));

$entityManager->persist($annualJob);
$entityManager->flush();
$entityManager->clear();

$jobs = $entityManager->createQuery(
    "SELECT j FROM Jobs j"
)->getResult();

echo $jobs[0]->getRange()->getStartDate()->format(DateTime::ISO8601); // "NOW"
echo $jobs[0]->getRange()->getEndDate()->format(DateTime::ISO8601); //  "NOW +1 year"

The Versions

23/06 2016

dev-master

9999999-dev https://github.com/Salamek/doctrine-daterange

Supports postgre DateRange in Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date range

23/06 2016

v1.1

1.1.0.0 https://github.com/Salamek/doctrine-daterange

Supports postgre DateRange in Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date range

23/06 2016

v1.0

1.0.0.0 https://github.com/Salamek/doctrine-daterange

Supports postgre DateRange in Doctrine DBAL.

  Sources   Download

MIT

The Requires

 

The Development Requires

doctrine date range