Last active
June 5, 2020 06:22
-
-
Save jonathanmaron/0f6128999bc5ff7c83c4bb91e8b2efdc to your computer and use it in GitHub Desktop.
PHP 7.4 implementation of the temporary change to VAT rates in Germany
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
// Here is a simple implementation in PHP 7.4 of the temporary change to VAT rates in Germany. | |
use DateTime; | |
use DateTimeZone; | |
/** | |
* Between July 1, 2020 and December 31, 2020 the VAT in Germany | |
* will sink from 19% to 16% (standard rate) and 7% to 5% (reduced rate). | |
* | |
* Source: https://tinyurl.com/y79lmh5f | |
*/ | |
$tz = new DateTimeZone('Europe/Berlin'); | |
$now = new DateTime('now', $tz); | |
$min = new DateTime('July 1, 2020 00:00:00', $tz); | |
$max = new DateTime('December 31, 2020 23:59:59', $tz); | |
if (in_range($now->getTimestamp(), $min->getTimestamp(), $max->getTimestamp(), true)) { | |
$data['DE'] = [ | |
'vat_rate_standard' => 16.0, | |
'vat_rate_reduced' => 5.0, | |
]; | |
} | |
// where "$data" is an array of VAT data as specified at https://euvatrates.com/rates.json and "in_range" is defined as: | |
/** | |
* Return true, if passed integer is in the range [min..max] | |
* | |
* @param int $int | |
* @param int $min | |
* @param int $max | |
* @param bool $inclusive | |
* | |
* @return bool | |
*/ | |
function in_range(int $int, int $min, int $max, bool $inclusive = false): bool | |
{ | |
if ($inclusive) { | |
return $int >= $min && $int <= $max; | |
} | |
return $int > $min && $int < $max; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment