Harvest_Range preset time periods

The Reporting features of the Harvest API allow you to set your time period when querying time entries and expenses. To simplify the task of pulling entries for the current or previous week/month the Harvest_Range class contains static methods to return an object preset to the given period. All of these functions take two parameters:

  • timeZone – The Time Zone to be used by default the server time zone is used but if your server is in a different time zone then you will want to set this parameter.
  • startOfWeek – The day of the week that your work week begins on. The default is set to Sunday (0) but you can pass in 1 if your week starts on Monday.

Harvest_Range set to this week

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$range = Harvest_Range::thisWeek( "EST", Harvest_Range::MONDAY );
<pre lang="PHP">$range = Harvest_Range::thisWeek();
</pre>
<h3>Harvest_Range set to the previous month</h3>
<pre lang="php">$range = Harvest_Range::lastMonth();
</pre>
<h3>Obtaining time entries logged against a project last week</h3>
<p>You can use these preset methods in conjunction with the reporting functions of the <a href="http://www.getharvest.com/api/" target="_blank">Harvest API</a>. For example you could get all the time entries logged for a project during the last week.</p>
<pre lang="php">$result = $api->getProjectEntries( 652605, new Harvest_Range::lastWeek( "EST" ) );
</pre>
$range = Harvest_Range::thisWeek( "EST", Harvest_Range::MONDAY ); <pre lang="PHP">$range = Harvest_Range::thisWeek(); </pre> <h3>Harvest_Range set to the previous month</h3> <pre lang="php">$range = Harvest_Range::lastMonth(); </pre> <h3>Obtaining time entries logged against a project last week</h3> <p>You can use these preset methods in conjunction with the reporting functions of the <a href="http://www.getharvest.com/api/" target="_blank">Harvest API</a>. For example you could get all the time entries logged for a project during the last week.</p> <pre lang="php">$result = $api->getProjectEntries( 652605, new Harvest_Range::lastWeek( "EST" ) ); </pre>
$range = Harvest_Range::thisWeek( "EST", Harvest_Range::MONDAY );

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$range = Harvest_Range::thisWeek();
$range = Harvest_Range::thisWeek();
$range = Harvest_Range::thisWeek();

Harvest_Range set to the previous month

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$range = Harvest_Range::lastMonth();
$range = Harvest_Range::lastMonth();
$range = Harvest_Range::lastMonth();

Obtaining time entries logged against a project last week

You can use these preset methods in conjunction with the reporting functions of the Harvest API. For example you could get all the time entries logged for a project during the last week.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$result = $api->getProjectEntries( 652605, new Harvest_Range::lastWeek( "EST" ) );
$result = $api->getProjectEntries( 652605, new Harvest_Range::lastWeek( "EST" ) );
$result = $api->getProjectEntries( 652605, new Harvest_Range::lastWeek( "EST" ) );

Comments & Questions

Add Your Comment