<?php
class timestrings {
protected $allLanguages;
protected $dataDir = __DIR__ . '/data/';
protected $lang;
protected $arr;
function __construct( $lang = false ) {
if ( false === $lang ) {
}
$lang = $this->repair_lang ( $lang );
$this->addLanguage( $lang );
}
function addLanguage( $lang ) {
$filename = $this->dataDir . 'date_names_by_number_' . $lang . '.ser';
$arr = $this->arr;
$this->arr = $arr;
$this->allLanguages[] = $lang;
$this->lang = $lang;
return true;
} else {
trigger_error("file '${filename}' not found or not readable.", E_USER_ERROR );
}
}
function setLanguage( $lang ) {
$lang = $this->repair_Lang ( $lang );
if (in_array( $lang, $this->allLanguages ) ) {
$this->lang = $lang;
} else {
$this->addLanguage ( $lang );
}
}
function repair_Lang( $lang ) {
return $lang;
}
function getWeekdayName( $i, $lang=false ) {
$i=(int) $i;
if ( $i > 7 or $i < 0 ) {
trigger_error( "Method:getWeekdayName: The given number of weekday ($i) is smaller then 0 or greater then 7" , E_USER_ERROR );
}
return $this->getIT (1, $i, $lang );
}
function getWeekdayShortName( $i, $lang=false ) {
$i=(int) $i;
if ( $i > 7 or $i < 0 ) {
trigger_error( "Method:getWeekdayShortName: The given number of weekday ($i) is smaller then 0 or greater then 7" , E_USER_ERROR );
}
return $this->getIT (0, $i, $lang );
}
function getMonthName( $i, $lang=false ) {
$i=(int) $i;
if ( $i > 12 or $i < 1 ) {
trigger_error( "Method:getMonthName: The given number of month ($i) is smaller then 0 or greater then 12" , E_USER_ERROR );
}
return $this->getIT (3, $i, $lang );
}
function getMonthShortName( $i, $lang=false ) {
$i=(int) $i;
if ( $i > 12 or $i < 1 ) {
trigger_error( "Method:getMonthName: The given number of month ($i) is smaller then 0 or greater then 12" , E_USER_ERROR );
}
return $this->getIT (2, $i, $lang );
}
function getIT ($k, $i, $lang ) {
if ( $lang ) {
$this->setLanguage( $lang );
}
if ( isset( $this->arr[$this->lang][$k][$i] ) ) {
return $this->arr[$this->lang][$k][$i];
} else {
trigger_error( "Unknown: arr[this->lang][${k}][${i}]" , E_USER_ERROR );
}
}
}