Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoerrmann committed Jun 23, 2020
0 parents commit ec0d667
Show file tree
Hide file tree
Showing 106 changed files with 10,781 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.php]
indent_size = 4

[*.md,*.txt]
trim_trailing_whitespace = false
insert_final_newline = false

[composer.json]
indent_size = 4
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Note: You need to uncomment the lines you want to use; the other lines can be deleted

# Git
# .gitattributes export-ignore
# .gitignore export-ignore

# Tests
# .coveralls.yml export-ignore
# .travis.yml export-ignore
# phpunit.xml.dist export-ignore
# tests/ export-ignore
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# OS files
.DS_Store

# npm modules
/node_modules

# files of Composer dependencies that are not needed for the plugin
/vendor/**/.*
/vendor/**/*.json
/vendor/**/*.txt
/vendor/**/*.md
/vendor/**/*.yml
/vendor/**/*.yaml
/vendor/**/*.xml
/vendor/**/*.dist
/vendor/**/readme.php
/vendor/**/LICENSE
/vendor/**/COPYING
/vendor/**/VERSION
/vendor/**/docs/*
/vendor/**/example/*
/vendor/**/examples/*
/vendor/**/test/*
/vendor/**/tests/*
/vendor/**/php4/*
/vendor/getkirby/composer-installer
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 hana+nils · Büro für Gestaltung

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Kirby Date Methods

Kirby 3 plugin providing field and page methods for formatting dates and creating PHP date objects.

## Installation

### Download

Download and copy this repository to `/site/plugins/date-methods`.

### Git submodule

```
git submodule add https://github.com/hananils/kirby-date-methods.git site/plugins/date-methods
```

### Composer

```
composer require hananils/kirby-date-methods
```

## Field methods

Field methods can be called on any field storing date information in a PHP-readable format.

### toDateTime()

Returns a `DateTime` representation of the field value, see [supported formats](https://www.php.net/manual/en/datetime.formats.php).

```php
$page->date()->toDateTime()
```

### toDateTimeImmutable()

Returns a `DateTimeImmutable` representation of the field value, see [supported formats](https://www.php.net/manual/en/datetime.formats.php).

```php
$page->date()->toDateTimeImmutable()
```

### toDateIntervale()

Returns a `DateInterval` representation of the field value, see [supported formats](https://www.php.net/manual/en/dateinterval.construct.php).

```php
$page->date()->toDateInterval()
```

### toDateDiff(\$to)

Returns a `DateInterval` object representing the difference between the field's date and the given date. The provided date can either be a `DateTime` object or a PHP-readable string, defaults to the difference to now.

```php
$page->date()->toDateDiff('+1 month')
```

### toFormatted($datetype, $timetype, $timezone, $calendar, \$pattern)

Returns a localized, formatted date using `IntlDateFormatter`, see [options](https://www.php.net/manual/de/intldateformatter.create.php). The locale is set based on the current Kirby language in a multilangual setup or on the `locale` config setting otherwise.

```php
// Returns 1. Januar 2020 for 2020-01-01 and de_DE
$page->date()->toFormatted();
```

### toRelative(\$from)

Returns a human readable time difference to the given date, e. g. `just now`, `2 years ago`, `in 5 minutes`. The given date can be a `DateTime` object or any PHP-readable date string, see [supported formats](https://www.php.net/manual/en/datetime.formats.php). Defaults to now.

```php
$page->date()->toRelative('next Monday');
```

### toCurrentYear()

Creates a `DateTime` representation of th field value and returns it with the year set to the current one.

```php
$page->date()->toCurrentYear();
```

### toCurrentMonth()

Creates a `DateTime` representation of th field value and returns it with the month set to the current one.

```php
$page->date()->toCurrentMonth();
```

### toCurrentDay()

Creates a `DateTime` representation of th field value and returns it with the day set to the current one.

```php
$page->date()->toCurrentDay();
```

### toAge($on, $format)

Calculates the difference difference between the field value and the given `on` date. Return the difference in the given format, defaults to years. See [format options](https://www.php.net/manual/de/dateinterval.format.php). Useful to calculate the age of a person.

```php
// Returns 10 given '2020-08-04'
$page->date()->toAge('2021-08-04')
```

## Pages methods

### toDateRange($fieldStart, $fieldEnd)

Returns a human-readable date range for the given dates:

- `$fieldStart`: the start date field name, defaults to 'start'
- `$fieldEnd`: the end date field name, defaults to 'end'

Returns a human-readable date range for the given dates and times:

- `$fieldStart`: an array of the start date and time field names, defaults to ['start', 'starttime']
- `$fieldEnd`: the end date and time field names, defaults to ['end', 'endtime']

The formatting is provided by [Ranger](https://github.com/flack/ranger).

## Helpers

### dateRelative($to, $from)

Returns a human readable time difference to the given dates, e. g. `just now`, `2 years ago`, `in 5 minutes`. The given dates can be `DateTime` objects or any PHP-readable date strings, see [supported formats](https://www.php.net/manual/en/datetime.formats.php).

```php
dateRelative('2019-12-31', 'now');
```

### dateFormatted($locale, $datetype, $timetype, $timezone, $calendar, $pattern)

Returns a localized, formatted date using `IntlDateFormatter`, see [options](https://www.php.net/manual/de/intldateformatter.create.php).

```php
dateFormatted('de_DE', '2020-01-01');
```

### dateRange($to, $from)

Returns a human readable time difference to the given dates, e. g. `just now`, `2 years ago`, `in 5 minutes`. The given dates can be `DateTime` objects or any PHP-readable date strings, see [supported formats](https://www.php.net/manual/en/datetime.formats.php).

```php
dateRange('2020-01-01', '2020-07-01');
```

### datetime(\$datetime)

Returns a `DateTime` object from the given date and time string. Directly returns the input if it's a `DateTime` object already.

## License

MIT

## Credits

[hana+nils · Büro für Gestaltung](https://hananils.de)
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "getkirby/pluginkit",
"description": "Kirby Example Plugin",
"type": "kirby-plugin",
"license": "MIT",
"authors": [
{
"name": "Your Name",
"email": "[email protected]"
}
],
"require": {
"getkirby/composer-installer": "^1.1",
"openpsa/ranger": "^0.5.1"
},
"autoload": {
"psr-4": {
"Superwoman\\Superplugin\\": "src/"
}
},
"config": {
"optimize-autoloader": true
}
}
Loading

0 comments on commit ec0d667

Please sign in to comment.