Skip to content

Commit efacdc9

Browse files
committed
Tests, readme and version bump for 5.1.0
1 parent 40ff7dc commit efacdc9

7 files changed

Lines changed: 670 additions & 77 deletions

File tree

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,58 @@ Example:
5454
{% set events = craft.entries.section('events').isFuture('dateRangeFieldHandle', 'entryTypeHandle') %}
5555
```
5656

57-
The plugin includes `isOnGoing()`, `isPast()`,`isNotPast()` and `isFuture()` query behaviors.
57+
The plugin includes the following query behaviors:
58+
- `isFuture()` - entries where the start date is in the future
59+
- `isPast()` - entries where the end date is in the past
60+
- `isNotPast()` - entries where the end date is in the future
61+
- `isOnGoing()` - entries where the start date is in the past and the end date is in the future
62+
- `startsAfterDate()` - entries where the start date is after the given date
63+
- `endsBeforeDate()` - entries where the end date is before the given date
64+
- `isDuringDate()` - entries where the date range overlaps with the given date or date range
65+
- `isNotDuringDate()` - entries where the date range does not overlap with the given date or date range
66+
5867
The second argument passed should be the handle of the entry type you want to query.
5968

60-
You can optionally pass `true` as a third argument to the query to make it include events that happen today in future/past/onGoing queries.
69+
You can optionally pass `true` as a third argument to `isFuture`, `isPast`, `isNotPast` and `isOnGoing` to include events that happen today.
70+
71+
The `startsAfterDate`, `endsBeforeDate`, `isDuringDate` and `isNotDuringDate` methods accept a date as the first argument, followed by the field handle and entry type handle:
72+
73+
```twig
74+
{# Entries starting after a specific date #}
75+
{% set events = craft.entries.section('events').startsAfterDate('2025-06-01', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
76+
77+
{# Entries ending before a specific date #}
78+
{% set events = craft.entries.section('events').endsBeforeDate('2025-12-31', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
79+
80+
{# Entries overlapping with a single date #}
81+
{% set events = craft.entries.section('events').isDuringDate('2025-06-15', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
82+
83+
{# Entries overlapping with a date range #}
84+
{% set events = craft.entries.section('events').isDuringDate('2025-06-01 => 2025-06-30', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
85+
86+
{# Entries NOT overlapping with a date range #}
87+
{% set events = craft.entries.section('events').isNotDuringDate('2025-06-01 => 2025-06-30', 'dateRangeFieldHandle', 'entryTypeHandle').all() %}
88+
```
6189

6290
### Field values
6391
When using the field in your template, you have access to both `start` and `end` properties, as well as:
6492
- `getFormatted()`: which optionally accepts a date(time) format (eg: 'd/m/Y') as the first parameter and a seperator string as the second (eg: ' until ').
6593
- `isPast`: returns `true` if the `end` property is past the current date & time.
6694
- `isFuture`: returns `true` if the `start` property is ahead the current date & time.
6795
- `isOnGoing`: returns `true` if the `start` property is past the current date & time *and* the `end` property is ahead of the current date & time.
96+
- `isNotPast`: returns `true` if the `end` property is ahead of the current date & time.
97+
- `startsAfterDate(date)`: returns `true` if the `start` property is after the given date.
98+
- `endsBeforeDate(date)`: returns `true` if the `end` property is before the given date.
99+
- `isDuringDate(date)`: returns `true` if the date range overlaps with the given date or date range.
100+
- `isNotDuringDate(date)`: returns `true` if the date range does not overlap with the given date or date range.
101+
102+
The `isDuringDate` and `isNotDuringDate` methods accept a single date string, a date range string (using `=>` as separator), or an array with `start` and `end` keys:
103+
104+
```twig
105+
{% if entry.dateRangeField.isDuringDate('2025-06-15') %}...{% endif %}
106+
{% if entry.dateRangeField.isDuringDate('2025-06-01 => 2025-06-30') %}...{% endif %}
107+
{% if entry.dateRangeField.isNotDuringDate('2025-07-01 => 2025-07-31') %}...{% endif %}
108+
```
68109

69110
### `getFormatted()`
70111
When using the ``getFormatted()`` function, you can pass paramters in 2 ways:
@@ -96,6 +137,19 @@ query{
96137
}
97138
}
98139
```
140+
141+
The following GraphQL query arguments are also available: `startsAfterDate`, `endsBeforeDate`, `isDuringDate`, and `isNotDuringDate`.
142+
143+
```graphql
144+
query{
145+
entries(
146+
section: "events",
147+
isDuringDate: ["2025-06-01 => 2025-06-30", "dateRangeFieldHandle", "entryTypeHandle"]
148+
) {
149+
title
150+
}
151+
}
152+
```
99153
----
100154

101155
Brought to you by [Studio Espresso](https://www.studioespresso.co)

composer.json

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
{
2-
"name": "studioespresso/craft-date-range",
3-
"description": "Date range field",
4-
"type": "craft-plugin",
5-
"version": "5.1.0-beta.1",
6-
"keywords": [
7-
"craft",
8-
"cms",
9-
"craftcms",
10-
"craft-plugin",
11-
"date range"
12-
],
13-
"support": {
14-
"docs": "https://github.com/studioespresso/craft-date-range/blob/master/README.md",
15-
"issues": "https://github.com/studioespresso/craft-date-range/issues"
16-
},
17-
"license": "MIT",
18-
"authors": [
19-
{
20-
"name": "Studio Espresso",
21-
"homepage": "https://www.studioespresso.co"
22-
}
23-
],
24-
"require": {
25-
"php": "^8.2",
26-
"craftcms/cms": "^5.0.0"
27-
},
28-
"require-dev": {
29-
"codeception/codeception": "^5.0.0",
30-
"codeception/module-asserts": "^3.0",
31-
"codeception/module-yii2": "^1.1.10",
32-
"craftcms/ecs": "dev-main",
33-
"craftcms/phpstan": "dev-main"
34-
},
35-
"scripts": {
36-
"check-cs": "ecs check --ansi",
37-
"fix-cs": "ecs check --ansi --fix",
38-
"phpstan": "phpstan --memory-limit=1G",
39-
"test": "codecept run unit"
40-
},
41-
"autoload": {
42-
"psr-4": {
43-
"studioespresso\\daterange\\": "src/"
44-
}
45-
},
46-
"extra": {
47-
"name": "Date Range Field",
48-
"handle": "date-range",
49-
"hasCpSettings": false,
50-
"hasCpSection": false,
51-
"changelogUrl": "https://raw.githubusercontent.com/studioespresso/craft-date-range/master/CHANGELOG.md",
52-
"class": "studioespresso\\daterange\\DateRange"
53-
},
54-
"funding": [
55-
{
56-
"type": "github",
57-
"url": "https://github.com/sponsors/janhenckens"
58-
}
59-
],
60-
"config": {
61-
"allow-plugins": {
62-
"yiisoft/yii2-composer": true,
63-
"craftcms/plugin-installer": true
64-
}
2+
"name": "studioespresso/craft-date-range",
3+
"description": "Date range field",
4+
"type": "craft-plugin",
5+
"version": "5.1.0",
6+
"keywords": [
7+
"craft",
8+
"cms",
9+
"craftcms",
10+
"craft-plugin",
11+
"date range"
12+
],
13+
"support": {
14+
"docs": "https://github.com/studioespresso/craft-date-range/blob/master/README.md",
15+
"issues": "https://github.com/studioespresso/craft-date-range/issues"
16+
},
17+
"license": "MIT",
18+
"authors": [
19+
{
20+
"name": "Studio Espresso",
21+
"homepage": "https://www.studioespresso.co"
6522
}
23+
],
24+
"require": {
25+
"php": "^8.2",
26+
"craftcms/cms": "^5.0.0"
27+
},
28+
"require-dev": {
29+
"codeception/codeception": "^5.0.0",
30+
"codeception/module-asserts": "^3.0",
31+
"codeception/module-yii2": "^1.1.10",
32+
"craftcms/ecs": "dev-main",
33+
"craftcms/phpstan": "dev-main"
34+
},
35+
"scripts": {
36+
"check-cs": "ecs check --ansi",
37+
"fix-cs": "ecs check --ansi --fix",
38+
"phpstan": "phpstan --memory-limit=1G",
39+
"test": "codecept run unit"
40+
},
41+
"autoload": {
42+
"psr-4": {
43+
"studioespresso\\daterange\\": "src/"
44+
}
45+
},
46+
"extra": {
47+
"name": "Date Range Field",
48+
"handle": "date-range",
49+
"hasCpSettings": false,
50+
"hasCpSection": false,
51+
"changelogUrl": "https://raw.githubusercontent.com/studioespresso/craft-date-range/master/CHANGELOG.md",
52+
"class": "studioespresso\\daterange\\DateRange"
53+
},
54+
"funding": [
55+
{
56+
"type": "github",
57+
"url": "https://github.com/sponsors/janhenckens"
58+
}
59+
],
60+
"config": {
61+
"allow-plugins": {
62+
"yiisoft/yii2-composer": true,
63+
"craftcms/plugin-installer": true
64+
}
65+
}
6666
}

src/behaviors/EntryQueryBehavior.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function isOnGoing($value, string|bool|null $entryTypeHandle = null, $inc
104104

105105
public function startsAfterDate(
106106
string|array $value,
107-
string|DateTimeInterface|int $date = null,
108-
string|bool $entryTypeHandle = null
107+
string|DateTimeInterface|int|null $date = null,
108+
string|bool|null $entryTypeHandle = null
109109
): Component|null {
110110
$value = $this->parseDateArgumentValue($value, $date, $entryTypeHandle);
111111

@@ -118,8 +118,8 @@ public function startsAfterDate(
118118

119119
public function endsBeforeDate(
120120
string|array $value,
121-
string|DateTimeInterface|int $date = null,
122-
string|bool $entryTypeHandle = null
121+
string|DateTimeInterface|int|null $date = null,
122+
string|bool|null $entryTypeHandle = null
123123
): Component|null {
124124
$value = $this->parseDateArgumentValue($value, $date, $entryTypeHandle);
125125

@@ -132,8 +132,8 @@ public function endsBeforeDate(
132132

133133
public function isDuringDate(
134134
string|array $value,
135-
string|DateTimeInterface|int $date = null,
136-
string|bool $entryTypeHandle = null
135+
string|DateTimeInterface|int|null $date = null,
136+
string|bool|null $entryTypeHandle = null
137137
): Component|null {
138138
$value = $this->parseDateRangeArgumentValue($value, $date, $entryTypeHandle);
139139

@@ -146,8 +146,8 @@ public function isDuringDate(
146146

147147
public function isNotDuringDate(
148148
string|array $value,
149-
string|DateTimeInterface|int $date = null,
150-
string|bool $entryTypeHandle = null
149+
string|DateTimeInterface|int|null $date = null,
150+
string|bool|null $entryTypeHandle = null
151151
): Component|null {
152152
$value = $this->parseDateRangeArgumentValue($value, $date, $entryTypeHandle);
153153

@@ -414,8 +414,8 @@ protected function parseArgumentValue(
414414

415415
protected function parseDateArgumentValue(
416416
string|array|DateTimeInterface|int $value,
417-
string $handle = null,
418-
string $entryTypeHandle = null
417+
?string $handle = null,
418+
?string $entryTypeHandle = null
419419
): array {
420420
$date = null;
421421

@@ -436,8 +436,8 @@ protected function parseDateArgumentValue(
436436

437437
protected function parseDateRangeArgumentValue(
438438
string|array|DateTimeInterface|int $value,
439-
string $handle = null,
440-
string $entryTypeHandle = null
439+
?string $handle = null,
440+
?string $entryTypeHandle = null
441441
): array {
442442
$dateRange = null;
443443

0 commit comments

Comments
 (0)