<?php

namespace App\Common;

class Helpers
{
    public static function peselBirthdayDate($pesel){
        $pesel = (String) $pesel;
        $output = $pesel[2];
        $output = (int)$output;
        if( $output == 0 || $output == 1){
            $year = '19'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 2 || $output == 3){
            $year = '20'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 4 || $output == 5){
            $year = '21'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 6 || $output == 7){
            $year = '22'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 8 || $output == 9){
            $year = '18'."".(String)$pesel[0]."".(String)$pesel[1];
        }

        if($output % 2 == 0  ){
            $month = '0'."".(String)$pesel[3];
        }else{
            $month = '1'."".(String)$pesel[3];
        }

        $day = (String)$pesel[4]."".(String)$pesel[5];

        return $day.".".$month.".".$year;
    }

    public static function peselBirthdayDateARRAY($pesel){
        $pesel = (String) $pesel;
        $output = $pesel[2];
        $output = (int)$output;
        if( $output == 0 || $output == 1){
            $year = '19'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 2 || $output == 3){
            $year = '20'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 4 || $output == 5){
            $year = '21'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 6 || $output == 7){
            $year = '22'."".(String)$pesel[0]."".(String)$pesel[1];
        }elseif( $output == 8 || $output == 9){
            $year = '18'."".(String)$pesel[0]."".(String)$pesel[1];
        }

        if($output % 2 == 0  ){
            $month = '0'."".(String)$pesel[3];
        }else{
            $month = '1'."".(String)$pesel[3];
        }

        $day = (String)$pesel[4]."".(String)$pesel[5];

        return array($day, $month, $year);
    }

    public static function textConvert($text){
        return iconv('utf-8','iso-8859-2',$text);
    }


}
