venca-x/date-cz

Nette addon. Convert month number to name or day number to name (CZ)

v1.1.0 2018-01-22 19:52 UTC

This package is auto-updated.

Last update: 2024-10-07 05:11:48 UTC


README

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

Nette addon for czech days and month names

Installation

Install plugin to your dependencies with composer:

composer require venca-x/date-cz:^1.1

For dev version install:

composer require venca-x/date-cz:dev-master

Configuration

Register filter for Nette/Layout. You do not have to use Nette/Layout, then call $dateCZ->getMonthName($text) in php code.

BasePresenter.php

use VencaX;
//...
protected function beforeRender()
{
    parent::beforeRender();

    $this->template->addFilter('monthNameCZ', function ($dayNumber) {
        $dateCZ = new VencaX\DateCZ();
        return $dateCZ->getMonthName($dayNumber);
    });
    
    $this->template->addFilter('dayNameCZ', function ($dayNumber) {
        $dateCZ = new VencaX\DateCZ();
        return $dateCZ->getDayName($dayNumber);
    });
    
    $this->template->addFilter('dayNameShortCZ', function ($dayNumber) {
        $dateCZ = new VencaX\DateCZ();
        return $dateCZ->getShortDayName($dayNumber);
    });
}

Usage

To display the correct day use PHP function for formating date:

Use in Nette/Layout:

{$dateTime->date|date:'n'|monthNameCZ} (* month name*)

{$dateTime->date|date:'N'|dayNameCZ} (* day name*)

{$dateTime->date|date:'N'|dayNameShortCZ} (* short day name*)

Use in PHP:

$dateCZ = new VencaX\DateCZ();
echo $dateCZ->monthNameCZ($dateTime->date->format('n')); //month name

echo $dateCZ->dayNameCZ($dateTime->date->format('N')); //day name

echo $dateCZ->dayNameShortCZ($dateTime->date->format('N')); //short day name

Output example

//monthNameCZ
echo $dateCZ->monthNameCZ(1); //leden
echo $dateCZ->monthNameCZ(2); //únor
echo $dateCZ->monthNameCZ(3); //březen
echo $dateCZ->monthNameCZ(4); //duben
echo $dateCZ->monthNameCZ(5); //květen
echo $dateCZ->monthNameCZ(6); //červen
echo $dateCZ->monthNameCZ(7); //červenec
echo $dateCZ->monthNameCZ(8); //srpen
echo $dateCZ->monthNameCZ(9); //září
echo $dateCZ->monthNameCZ(10); //říjen
echo $dateCZ->monthNameCZ(11); //listopad
echo $dateCZ->monthNameCZ(12); //prosinec

//dayNameCZ
echo $dateCZ->dayNameCZ(1); //pondělí
echo $dateCZ->dayNameCZ(2); //úterý
echo $dateCZ->dayNameCZ(3); //středa
echo $dateCZ->dayNameCZ(4); //čtvrtek
echo $dateCZ->dayNameCZ(5); //pátek
echo $dateCZ->dayNameCZ(6); //sobota
echo $dateCZ->dayNameCZ(7); //neděle

//dayNameShortCZ
echo $dateCZ->dayNameShortCZ(1); //po
echo $dateCZ->dayNameShortCZ(2); //út
echo $dateCZ->dayNameShortCZ(3); //st
echo $dateCZ->dayNameShortCZ(4); //čt
echo $dateCZ->dayNameShortCZ(5); //pá
echo $dateCZ->dayNameShortCZ(6); //so
echo $dateCZ->dayNameShortCZ(7); //ne