Giter Club home page Giter Club logo

yii-x's Introduction

Yii-x набор компонент для Yii

Установка

  • git submodule add [email protected]:stden/yii-x.git <application>/protected/extensions/yii-x
  • Добавить следующие строки в файл конфигурации protected/config/main.php:
<?php
...
	'import'=>array(
        // Компоненты yii-x
        'ext.yii-x.*',
	),
...
...

Использование

Работа с днями рождений

<?php

require_once dirname(__FILE__) . '/../bootstrap.php';

class BirthdayTest extends CDbTestCase
{
    public function setUp()
    {
        parent::setUp();
    }

    /**
     * Добавление дня рождения
     * @return void
     */
    public function testAddBirthday()
    {
        $b = new DateUtils();
        $b->today = new DateTime();

        $d = clone $b->today;
        $origin = clone $d; // Сохраняем исходное значение
        $this->assertEquals($d, $b->NextTime($d));

        $d->sub(new DateInterval("P1D")); // Событие было вчера
        // Следующий раз оно будет через год минус 1 день
        $n = clone $origin;
        $n->add(new DateInterval("P1Y"));
        $n->sub(new DateInterval("P1D"));
        $d_origin = clone $d;
        $this->assertEquals($n, $b->NextTime($d));
        $this->assertEquals($d_origin, $d);

        $t1 = new DateTime();
        $t2 = new DateTime();
        $t = $t1->diff($t2);
        echo $t->format('%R%');

        Yii::app()->language = 'ru';
        $r = $b->calc($b->today);
        $this->assertEquals(array('days' => 0, 'm' => 0, 'd' => 0, 'diff' => 'Сегодня!'), $r);

        Yii::app()->language = 'en';
        $r = $b->calc($b->today);
        $this->assertEquals(array('days' => 0, 'm' => 0, 'd' => 0, 'diff' => 'Today!'), $r);
    }

    public function testReminderMessage()
    {
        $tests = array(
            1 => 'Завтра',
            2 => '1 день',
            3 => '2 дня',
            4 => '3 дня',
            5 => '4 дня',
            6 => '5 дней'
        );

        Yii::app()->language = 'ru';
        foreach ($tests as $days => $str) {
            $b = new DateUtils();
            $d = clone $b->today;
            $d->add(new DateInterval("P{$days}D"));
            $r = $b->calc($d);
            $this->assertEquals(array('days' => $days, 'm' => 0, 'd' => $days, 'diff' => $str), $r);
        }
    }

}

yii-x's People

Contributors

stden avatar

Stargazers

Sergey avatar  avatar Zhukov Sergei avatar Vladimir Ponomarev avatar Myroslav avatar  avatar

Watchers

 avatar James Cloos avatar

Forkers

level0r0s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.