Skip to content

Commit

Permalink
feat: add firstSecond() and lastSecond()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Feb 12, 2023
1 parent fff1283 commit f0eb68c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .vscode/RockMigrations.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
],
"description": "Add a text field via RockMigrations"
},
"rmf-integer": {
"prefix": "rmf-integer",
"body": [
"$1 => [",
" 'type' => 'integer',",
" 'label' => '$3',",
" 'icon' => 'list-ol',",
"],"
],
"description": "Add an integer field via RockMigrations"
},
"rmf-url": {
"prefix": "rmf-url",
"body": [
Expand Down
29 changes: 28 additions & 1 deletion RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ProcessWire;

use DateTime;
use DirectoryIterator;
use ProcessWire\WireArray as ProcessWireWireArray;
use RockMatrix\Block as RockMatrixBlock;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static function getModuleInfo()
{
return [
'title' => 'RockMigrations',
'version' => '2.16.0',
'version' => '2.17.0',
'summary' => 'The Ultimate Automation and Deployment-Tool for ProcessWire',
'autoload' => 2,
'singular' => true,
Expand Down Expand Up @@ -1441,6 +1442,17 @@ public function fireOnRefresh($module, $method = null, $priority = [])
return;
}

/**
* Get first second of year/month/day
*/
public function firstSecond($year, $month = null, $day = null): int
{
$date = new DateTime();
$date->setDate($year, $month ?: 1, $day ?: 1);
$date->setTime(0, 0, 0);
return $date->getTimestamp();
}

/**
* Run migrations during development on every request
* This is handy to code rapidly and get instant output via RockFrontend's
Expand Down Expand Up @@ -2082,6 +2094,21 @@ public function lastmodified()
return $last;
}

/**
* Get last second of year/month/day
*/
public function lastSecond($year, $month = null, $day = null): int
{
$date = new DateTime();
$date->setDate($year, $month ?: 1, $day ?: 1);
$date->setTime(0, 0, 0);
if ($day) $date->modify("+1 day");
elseif ($month) $date->modify("+1 month");
elseif ($year) $date->modify("+1 year");
$date->modify("-1 second");
return $date->getTimestamp();
}

/**
* Load files on demand on local installation
*
Expand Down

0 comments on commit f0eb68c

Please sign in to comment.