Skip to content

Commit

Permalink
Version 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Apr 7, 2021
2 parents a0c747c + 4f848f1 commit 2c9fa8d
Show file tree
Hide file tree
Showing 9 changed files with 662 additions and 67 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# (MODX)EvolutionCMS.snippets.ddGetDate changelog


## Version 2.2 (2021-04-07)
* \* Attention! PHP >= 5.6 is required.
* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.48 is required.
* \+ You can just call `\DDTools\Snippet::runSnippet` to run the snippet without DB and eval (see README → Examples).
* \+ `\ddGetDate\Snippet`: The new class. All snippet code was moved here.
* \+ README.
* \+ README_ru.
* \+ CHANGELOG.
* \+ CHANGELOG_ru.
* \+ Composer.json.


## Version 2.1.2 (2014-07-13)
* \* Bugfix: undeclared variables in PHP 5.3.
* \* The redundant code has been removed.


## Version 2.1.1 (2012-03-16)
* \+ Added English support for short formated date (if used `shortFormat`).


## Version 2.1 (2012-03-05)
* \+ Added English support in month names (if `monthToStr` equals `1`).


## Version 2.0 (2012-01-23)
* \* Attention! Backward compatibility is broken.
* \* Parameters → `date`:
* \+ Now supports not only unixtime. Added unixtime check and converting with `strtotime()`.
* \* Value `'current'` was replaced to `'now'` (`strtotime()` native support).


## Version 1.9 (2010-11-23)
* \* Minor optimization.


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
<style>ul{list-style:none;}</style>
41 changes: 41 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# (MODX)EvolutionCMS.snippets.ddGetDate changelog


## Версия 2.2 (2021-04-07)
* \* Внимание! Требуется PHP >= 5.6.
* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.48.
* \+ Запустить сниппет без DB и eval можно через `\DDTools\Snippet::runSnippet` (см. примеры в README).
* \+ `\ddGetDate\Snippet`: Новый класс. Весь код сниппета перенесён туда.
* \+ README.
* \+ README_ru.
* \+ CHANGELOG.
* \+ CHANGELOG_ru.
* \+ Composer.json.


## Версия 2.1.2 (2014-07-13)
* \* Исправлена ошибка с обращением к не объявленным переменным (PHP 5.3).
* \* Удалён избыточный код.


## Версия 2.1.1 (2012-03-16)
* \+ Добавлен вывод даты в коротком формате на английском (при использовании параметра `shortFormat`).


## Версия 2.1 (2012-03-05)
* \+ Добавлен вывод месяцев на английском (при `monthToStr` равном `1`).


## Версия 2.0 (2012-01-23)
* \* Внимание! Нарушена обратная совместимость.
* \* Parameters → `date`:
* \+ Дату теперь можно передавать не только в unixtime. Добавлена проверка даты на UNIX-формат, добавлено преобразование через `strtotime()`.
* \* Вместо возможного значения `'current'` теперь значение `'now'` (обусловленно тем, что функция `strtotime` понимает `'now'` сама).


## Версия 1.9 (2010-11-23)
* \* Небольшая оптимизация.


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
<style>ul{list-style:none;}</style>
161 changes: 157 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,158 @@
# ddGetDate
# (MODX)EvolutionCMS.snippets.ddGetDate

Snippet returns the date in a specified format.
___
Visit the following [link](http://code.divandesign.biz/modx/ddgetdate) to read the documentation, instructions & changelog.
Snippet returns the date in a specified format. It can also:
* Return the current date;
* Return document pubdate by default, or createon if pubdate is empty;
* Display month as a string (like `January`, `February`, `March`, etc);
* Return short formated date (like `Today`, `Yesterday`, `Day before yesterday`).


## Requires

* PHP >= 5.6
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.48


## Documentation


### Installation


#### 1. Elements → Snippets: Create a new snippet with the following data

1. Snippet name: `ddGetDate`.
2. Description: `<b>2.2</b> Snippet returns the date in a specified format.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddGetDate_snippet.php` file from the archive.


#### 2. Elements → Manage Files

1. Create a new folder `assets/snippets/ddGetDate/`.
2. Extract the archive to the folder (except `ddGetDate_snippet.php`).


### Parameters description

* `date`
* Desctription: Date.
* Valid values:
* `integer`
* `string`
* `'now'` — current date
* Default value: Pubdate or createdon (if pubdate is empty).

* `format`
* Desctription: Date format to display.
* Valid values: `string`
* Default value: `'d.m.y'`

* `monthToStr`
* Desctription: Display month as string. If it's true month in `format` must be specified as `'month'`.
* Valid values:
* `0`
* `1`
* Default value: `0`

* `shortFormat`
* Desctription: Display shorted fromated date. If it's true date in `shortFormat` must be specified as `'short'`.
* Valid values: `string`
* Default value: —

* `lang`
* Desctription: Month names language.
* Valid values:
* `'ru'`
* `'en'`
* Default value: `'ru'`


### Examples


#### Get current year

```
[[ddGetDate?
&date=`now`
&format=`Y`
]]
```

Returns:

```
2021
```


#### Get document `pubdate` or `creadeon` (if `pubdate` is empty)

```
[[ddGetDate]]
```

Returns:

```
27.03.21
```


#### Get some TV-date with month name to string

```
[[ddGetDate?
&date=`[*tvDate*]`
&format=`d month Y`
&monthToStr=`1`
&lang=`en`
]]
```

Returns:

```
27 March 2021
```


#### Get date in short format (for example, today is 28.03.2021)

```
[[ddGetDate?
&shortFormat=`short, G:i`
]]
```

Returns:

```
Yesterday, 9:48.
```


#### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

```php
\DDTools\Snippet::runSnippet([
'name' => 'ddGetDate',
'params' => [
'date' => 'now',
'format' => 'd.m.Y'
]
]);
```


## Links

* [Home page](https://code.divandesign.biz/modx/ddgetdate)
* [Telegram chat](https://t.me/dd_code)
* [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddgetdate)


<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />
Loading

0 comments on commit 2c9fa8d

Please sign in to comment.