Skip to content

Commit

Permalink
prevent end/duration from existing on the same ics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Milloy committed Feb 27, 2019
1 parent e4945f5 commit cab6ea2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v0.1.7

Add ability to set duration

## v0.1.4

Add ability to export tempfile
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ $event = NowCal::create(['start' => 'October 5, 2019 6:03PM']))

### Properties

The following properties can be get/set on the NowCal instance. Users should take advantage of the setting property helpers in the class, i.e.: `$nowcal->location('Event Location');` as they provide a nice syntax to string multiple calls together.

| Property | Type | Description |
| -------- | ------ | ----------------------------------------------------- |
| start | string | A DateTime compatible string that is parsed by Carbon |
| end | string | A DateTime compatible string that is parsed by Carbon |
| summary | string | A short description of the event |
| location | string | The location where the event is taking place |
The following properties can be get/set on the NowCal instance. Users can take advantage of the set property helpers in the class, i.e.: `$nowcal->location('Event Location');` as they provide a nice syntax to string multiple calls together and support callbacks if necessary.

| Property | Description |
| -------- | ------------------------------------------------------------------------------------------------------ |
| start | A string parseable by Carbon |
| end | A string parseable by Carbon, as per RFC 5545, only an end value or duration value may be used |
| duration | A string parseable by CarbonInterval, as per RFC 5545, only an end value or duration value may be used |
| summary | A short description of the event |
| location | The location where the event is taking place |

### Methods

Expand Down
10 changes: 7 additions & 3 deletions src/NowCal/Traits/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public function start($datetime): self
*/
public function end($datetime): self
{
$this->set('end', $datetime);
if (null === $this->duration) {
$this->set('end', $datetime);
}

return $this;
}
Expand Down Expand Up @@ -176,15 +178,17 @@ public function location($location): self
}

/**
* Set the event's duration.
* Set the event's duration using a CarbonInterval parsable string.
*
* @param mixed $location'
*
* @return \NowCal\NowCal
*/
public function duration($duration): self
{
$this->set('duration', $duration);
if (null === $this->end) {
$this->set('duration', $duration);
}

return $this;
}
Expand Down
16 changes: 15 additions & 1 deletion tests/NowCal/DurationAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function it_can_get_set_a_duration()
public function it_casts_end_as_an_iso_duration()
{
$this->nowcal->duration($duration = '1h');
var_dump($this->nowcal->plain);

$this->assertStringContainsString(CarbonInterval::fromString($duration)->spec(), $this->nowcal->plain);
}
Expand All @@ -39,5 +38,20 @@ public function it_can_take_a_callback_as_a_value()
/** @test */
public function it_cannot_have_both_an_end_and_duration()
{
$duration = '1h';
$end = 'now';

$this->nowcal->duration($duration)
->end($end);

$this->assertEquals(null, $this->nowcal->end);
$this->assertEquals($duration, $this->nowcal->duration);

$this->nowcal = $this->createNowCalInstance();
$this->nowcal->end($end)
->duration($duration);

$this->assertEquals(null, $this->nowcal->duration);
$this->assertEquals($end, $this->nowcal->end);
}
}
5 changes: 5 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public function setUp(): void

$this->nowcal = new NowCal([]);
}

protected function createNowCalInstance()
{
return new Nowcal([]);
}
}

0 comments on commit cab6ea2

Please sign in to comment.