Skip to content

Commit

Permalink
Updating dates to objects
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Oct 7, 2016
1 parent 5612942 commit a1dbbcf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All Notable changes to `jobs-usajobs` will be documented in this file

## 0.2.0 - 2016-09-17

### Fixed
- Saving all date fields as `DateTime` objects rather than strings.

## 0.1.0 - 2016-09-17

### Added
Expand Down
30 changes: 26 additions & 4 deletions src/Providers/UsajobsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ public function createJobObject($payload = [])
'name' => $payload['PositionTitle'],
'url' => $payload['PositionURI'],
'qualifications' => $payload['QualificationSummary'],
'datePosted' => $payload['PublicationStartDate'],
'validThrough' => $payload['ApplicationCloseDate'],
'startDate' => $payload['PositionStartDate'],
'endDate' => $payload['PositionEndDate'],
]);

$job->setCompany($payload['OrganizationName']);

$job = $this->setDates($payload, $job);
$job = $this->setNestedProperties($payload, $job);
$job = $this->setSalary($payload['PositionRemuneration'], $job);
return $this->setLocation($payload['PositionLocation'], $job);
Expand Down Expand Up @@ -64,6 +61,31 @@ public function getListingsPath()
return 'SearchResult.SearchResultItems';
}

/**
* Sets nested properties
*
* @param $payload array
* @param $job \JobApis\Jobs\Client\Job
*
* @return \JobApis\Jobs\Client\Job
*/
protected function setDates($payload, $job)
{
$dateFields = [
'PublicationStartDate' => 'datePosted',
'ApplicationCloseDate' => 'validThrough',
'PositionStartDate' => 'startDate',
'PositionEndDate' => 'endDate',
];
foreach ($dateFields as $key => $field) {
if (strtotime($payload[$key]) !== false) {
$job->{'set'.ucfirst($field)}(new \DateTime($payload[$key]));
}
}

return $job;
}

/**
* Sets nested properties
*
Expand Down
4 changes: 4 additions & 0 deletions tests/src/UsajobsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function testItCanCreateJobObjectFromPayload()
$this->assertEquals($payload['MatchedObjectId'], $results->sourceId);
$this->assertEquals($payload['MatchedObjectDescriptor']['PositionTitle'], $results->title);
$this->assertEquals($payload['MatchedObjectDescriptor']['PositionURI'], $results->url);
$this->assertEquals(\DateTime::class, get_class($results->datePosted));
$this->assertEquals(\DateTime::class, get_class($results->validThrough));
$this->assertEquals(\DateTime::class, get_class($results->startDate));
$this->assertEquals(\DateTime::class, get_class($results->endDate));
}

/**
Expand Down

0 comments on commit a1dbbcf

Please sign in to comment.