<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# Date functions
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************


//-------------------------for rss reader---------------------------------------------------
function Formatdate2($rawdate,$type)
{
	$arraytemp = explode(",", $rawdate);
	$arraytemp2=explode(" ",$arraytemp[1]);
	$arraytemp3=explode(":",$arraytemp2[4]);

	$array[0]=$arraytemp[0];
	$array[1]=$arraytemp2[1];
	$array[2]=$arraytemp2[2];
	$array[3]=$arraytemp2[3];
	$array[4]=$arraytemp3[0];
	$array[5]=$arraytemp3[1];

	return $array[$type];
}

//french date in for Rss reader
function rssToDate($rawdate)
{
	$mois = array('Jan'=>''.lg("janvier").'','Feb'=>''.lg("fevrier").'', 'Mar'=>''.lg("mars").'','Apr'=>''.lg("avril").'','May'=>''.lg("mai").'','Jun'=>''.lg("juin").'','Jul'=>''.lg("juillet").'','Aug'=>''.lg("aout").'','Sep'=>''.lg("septembre").'','Oct'=>''.lg("octobre").'','Nov'=>''.lg("novembre").'','Dec'=>''.lg("decembre").'');
	$jours= array('Sun'=>''.lg("dimanche").'','Mon'=>''.lg("lundi").'','Tue'=>''.lg("mardi").'','Wed'=>''.lg("mercredi").'','Thu'=>''.lg("jeudi").'','Fri'=>''.lg("vendredi").'','Sat'=>''.lg("samedi").'');

	return $jours[Formatdate2($rawdate,0)].' '.Formatdate2($rawdate,1).' '.$mois[Formatdate2($rawdate,2)].' '.Formatdate2($rawdate,3);
}

function formatDate($_date,$today='',$yesterday='')
{
	if (!empty($today) && $_date==$today)
	{
		return lg("today");
	}
	else if (!empty($yesterday) && $_date==$yesterday)
	{
		return lg("yesterday");
	}
	else
	{
		$dateElmt = explode("-", $_date);
		$year=$dateElmt[0];
		$month=$dateElmt[2];
		$day=$dateElmt[1];
	
		if(__LANG == 'en')
		{
			return $month.'/'.$day.'/'.$year;
		}
		else
		{
			return $day.'/'.$month.'/'.$year;
		}
	}
}
function getToday()
{
	return date('Y-m-d');
}
function getYesterday()
{
	return date('Y-m-d', time() - 86400);
}
function getLastWeek()
{
	return date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-7,  date("Y")));
}
function getDBDate($_date)
{
	return substr($_date,0,10);
}
//--------------------------------------------------------------------------------------------
?>