Skip to content

Commit

Permalink
Add method to search nameday date by name
Browse files Browse the repository at this point in the history
  • Loading branch information
dfridrich committed Mar 28, 2016
1 parent a464dd0 commit 83fcc7b
Showing 1 changed file with 61 additions and 28 deletions.
89 changes: 61 additions & 28 deletions src/NameDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Defr;

/**
* Class NameDays.
*
* Class NameDays
* @package Defr
* @author Dennis Fridrich <[email protected]>
*/
class NameDays
{
/**
* @var array
*/
private static $data = array(
1 => array(
private static $data = [
1 => [
1 => '!Nový rok',
'Karina',
'Radmila',
Expand Down Expand Up @@ -45,8 +45,8 @@ class NameDays
'Zdislava',
'Robin',
'Marika',
),
array(
],
[
1 => 'Hynek',
'Nela',
'Blažej',
Expand Down Expand Up @@ -76,8 +76,8 @@ class NameDays
'Alexandr',
'Lumír',
'Horymír',
),
array(
],
[
1 => 'Bedřich',
'Anežka',
'Kamil',
Expand Down Expand Up @@ -109,8 +109,8 @@ class NameDays
'Taťána',
'Arnošt',
'Kvido',
),
array(
],
[
1 => 'Hugo',
'Erika',
'Richard',
Expand Down Expand Up @@ -141,8 +141,8 @@ class NameDays
'Vlastislav',
'Robert',
'Blahoslav',
),
array(
],
[
1 => '!Svátek práce',
'Zikmund',
'Alexej',
Expand Down Expand Up @@ -174,8 +174,8 @@ class NameDays
'Maxmilián',
'Ferdinand',
'Kamila',
),
array(
],
[
1 => 'Laura',
'Jarmil',
'Tamara',
Expand Down Expand Up @@ -206,8 +206,8 @@ class NameDays
'Lubomír',
'Petr/Pavel',
'Šárka',
),
array(
],
[
1 => 'Jaroslava',
'Patricie',
'Radomír',
Expand Down Expand Up @@ -239,8 +239,8 @@ class NameDays
'Marta',
'Bořivoj',
'Ignác',
),
array(
],
[
1 => 'Oskar',
'Gustav',
'Miluše',
Expand Down Expand Up @@ -272,8 +272,8 @@ class NameDays
'Evelína',
'Vladěna',
'Pavlína',
),
array(
],
[
1 => 'Linda/Samuel',
'Adéla',
'Bronislav',
Expand Down Expand Up @@ -304,8 +304,8 @@ class NameDays
'Václav',
'Michal',
'Jeroným',
),
array(
],
[
1 => 'Igor',
'Olívie/Oliver',
'Bohumil',
Expand Down Expand Up @@ -337,8 +337,8 @@ class NameDays
'Silvie',
'Tadeáš',
'Štěpánka',
),
array(
],
[
1 => 'Felix',
'!Památka zesnulých',
'Hubert',
Expand Down Expand Up @@ -369,8 +369,8 @@ class NameDays
'René',
'Zina',
'Ondřej',
),
array(
],
[
1 => 'Iva',
'Blanka',
'Svatoslav',
Expand Down Expand Up @@ -402,8 +402,8 @@ class NameDays
'Judita',
'David',
'Silvestr',
),
);
],
];

/**
* @param \DateTime $date
Expand All @@ -424,4 +424,37 @@ public static function getNameDay(\DateTime $date = null)

return $return;
}

/**
* @param $name
* @return \DateTime|null
*/
public static function getNameDate($name)
{
$matches = [];
for ($i = 1; $i <= 12; $i++) {
foreach (self::$data[$i] as $day => $value) {
$check = mb_stripos($value, $name);
if (false !== $check) {
$matches[] = [$i, $day, $value, levenshtein($name, $value)];
}
}
}

usort(
$matches,
function ($a, $b) {
return $a[3] > $b[3];
}
);

if (count($matches) == 0) {
return null;
}

$date = new \DateTime();
$date->setDate(0, $matches[0][0], $matches[0][1]);

return $date;
}
}

0 comments on commit 83fcc7b

Please sign in to comment.