dolibarr  7.0.0-beta
Functions
date.lib.php File Reference

Set of function to manipulate dates. More...

Go to the source code of this file.

Functions

 get_tz_array ()
 Return an array with timezone values. More...
 
 getServerTimeZoneString ()
 Return server timezone string. More...
 
 getServerTimeZoneInt ($refgmtdate='now')
 Return server timezone int. More...
 
 dol_time_plus_duree ($time, $duration_value, $duration_unit)
 Add a delay to a date. More...
 
 convertTime2Seconds ($iHours=0, $iMinutes=0, $iSeconds=0)
 Convert hours and minutes into seconds. More...
 
 convertSecondToTime ($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
 Return, in clear text, value of a number of seconds in days, hours and minutes. More...
 
 dol_stringtotime ($string, $gm=1)
 Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not supported. More...
 
 dol_get_prev_day ($day, $month, $year)
 Return previous day. More...
 
 dol_get_next_day ($day, $month, $year)
 Return next day. More...
 
 dol_get_prev_month ($month, $year)
 Return previous month. More...
 
 dol_get_next_month ($month, $year)
 Return next month. More...
 
 dol_get_prev_week ($day, $week, $month, $year)
 Return previous week. More...
 
 dol_get_next_week ($day, $week, $month, $year)
 Return next week. More...
 
 dol_get_first_day ($year, $month=1, $gm=false)
 Return GMT time for first day of a month or year. More...
 
 dol_get_last_day ($year, $month=12, $gm=false)
 Return GMT time for last day of a month or year. More...
 
 dol_get_first_day_week ($day, $month, $year, $gm=false)
 Return first day of week for a date. More...
 
 num_public_holiday ($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
 Fonction retournant le nombre de jour feries, samedis et dimanches entre 2 dates entrees en timestamp. More...
 
 num_between_day ($timestampStart, $timestampEnd, $lastday=0)
 Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 2012-01-02 => 1 if lastday=0, 2 if lastday=1. More...
 
 num_open_day ($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
 Function to return number of working days (and text of units) between two dates (working days) More...
 
 monthArray ($outputlangs, $short=0)
 Return array of translated months or selected month. More...
 

Detailed Description

Set of function to manipulate dates.

Definition in file date.lib.php.

Function Documentation

convertSecondToTime (   $iSecond,
  $format = 'all',
  $lengthOfDay = 86400,
  $lengthOfWeek = 7 
)

Return, in clear text, value of a number of seconds in days, hours and minutes.

Can be used to show a duration.

Parameters
int$iSecondNumber of seconds
string$formatOutput format ('all': total delay days hour:min like "2 days 12:30", 'allwithouthour': total delay days without hour part like "2 days", 'allhourmin': total delay with format hours:min like "60:30", 'allhour': total delay hours without min/sec like "60:30", 'fullhour': total delay hour decimal like "60.5" for 60:30, 'hour': only hours part "12", 'min': only minutes part "30", 'sec': only seconds part, 'month': only month part, 'year': only year part);
int$lengthOfDayLength of day (default 86400 seconds for 1 day, 28800 for 8 hour)
int$lengthOfWeekLength of week (default 7)
Returns
string Formated text of duration Example: 0 return 00:00, 3600 return 1:00, 86400 return 1d, 90000 return 1 Day 01:00
See also
convertTime2Seconds

Definition at line 171 of file date.lib.php.

References dol_print_date().

Referenced by build_calfile(), constructGanttLine(), doc_generic_task_odt\get_substitutionarray_taskstime(), doc_generic_project_odt\get_substitutionarray_taskstime(), print_projecttasks_array(), projectLinesa(), projectLinesPerAction(), projectLinesPerDay(), projectLinesPerWeek(), pdf_baleine\write_file(), pdf_soleil\write_file(), and pdf_strato\write_file().

convertTime2Seconds (   $iHours = 0,
  $iMinutes = 0,
  $iSeconds = 0 
)

Convert hours and minutes into seconds.

Parameters
int$iHoursHours
int$iMinutesMinutes
int$iSecondsSeconds
Returns
int Time into seconds
See also
convertSecondToTime

Definition at line 153 of file date.lib.php.

dol_get_first_day (   $year,
  $month = 1,
  $gm = false 
)

Return GMT time for first day of a month or year.

Parameters
int$yearYear
int$monthMonth
mixed$gmFalse or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date. Exemple: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, after a dol_print_date will return 1970-01-01 00:00:00 Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, after a dol_print_date will return 1970-01-01 00:00:00
Returns
int Date for first day, '' if error

Definition at line 445 of file date.lib.php.

References dol_mktime().

Referenced by CommActionRapport\_pages(), ActionComm\build_exportfile(), TaskStats\buildWhere(), ProjectStats\buildWhere(), FichinterStats\getAllByProduct(), CommandeStats\getAllByProduct(), FactureStats\getAllByProduct(), PropaleStats\getAllByProduct(), FichinterStats\getAmountByMonth(), FactureStats\getAmountByMonth(), CommandeStats\getAmountByMonth(), PropaleStats\getAmountByMonth(), FichinterStats\getAverageByMonth(), CommandeStats\getAverageByMonth(), FactureStats\getAverageByMonth(), PropaleStats\getAverageByMonth(), DonationStats\getNbByMonth(), ExpeditionStats\getNbByMonth(), FichinterStats\getNbByMonth(), FactureStats\getNbByMonth(), CommandeStats\getNbByMonth(), PropaleStats\getNbByMonth(), box_task\loadBox(), tax_by_date(), vat_by_thirdparty(), and pdf_paiement\write_file().

dol_get_first_day_week (   $day,
  $month,
  $year,
  $gm = false 
)

Return first day of week for a date.

First day of week may be monday if option MAIN_START_WEEK is 1.

Parameters
int$dayDay
int$monthMonth
int$yearYear
int$gmFalse or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
Returns
array year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year

Definition at line 487 of file date.lib.php.

References dol_getdate(), and dol_mktime().

Referenced by displayBox(), dol_get_next_week(), and dol_get_prev_week().

dol_get_last_day (   $year,
  $month = 12,
  $gm = false 
)
dol_get_next_day (   $day,
  $month,
  $year 
)

Return next day.

Parameters
int$dayDay
int$monthMonth
int$yearYear
Returns
array Next year,month,day

Definition at line 348 of file date.lib.php.

References dol_getdate(), and dol_mktime().

Referenced by getCommonSubstitutionArray(), and GETPOST().

dol_get_next_month (   $month,
  $year 
)

Return next month.

Parameters
int$monthMonth
int$yearYear
Returns
array Next year,month

Definition at line 383 of file date.lib.php.

Referenced by getCommonSubstitutionArray(), and GETPOST().

dol_get_next_week (   $day,
  $week,
  $month,
  $year 
)

Return next week.

Parameters
int$dayDay
int$weekWeek
int$monthMonth
int$yearYear
Returns
array Next year,month,day

Definition at line 424 of file date.lib.php.

References dol_get_first_day_week(), dol_getdate(), and dol_mktime().

dol_get_prev_day (   $day,
  $month,
  $year 
)

Return previous day.

Parameters
int$dayDay
int$monthMonth
int$yearYear
Returns
array Previous year,month,day

Definition at line 333 of file date.lib.php.

References dol_getdate(), and dol_mktime().

Referenced by getCommonSubstitutionArray(), and GETPOST().

dol_get_prev_month (   $month,
  $year 
)

Return previous month.

Parameters
int$monthMonth
int$yearYear
Returns
array Previous year,month

Definition at line 362 of file date.lib.php.

Referenced by getCommonSubstitutionArray(), and GETPOST().

dol_get_prev_week (   $day,
  $week,
  $month,
  $year 
)

Return previous week.

Parameters
int$dayDay
int$weekWeek
int$monthMonth
int$yearYear
Returns
array Previous year,month,day

Definition at line 406 of file date.lib.php.

References dol_get_first_day_week(), dol_getdate(), and dol_mktime().

dol_stringtotime (   $string,
  $gm = 1 
)

Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not supported.

If parameter gm is 1, we will use no TZ, if not we will use TZ of server, not the one inside string.

Parameters
string$stringDate in a string YYYYMMDD YYYYMMDDHHMMSS YYYYMMDDTHHMMSSZ YYYY-MM-DDTHH:MM:SSZ (RFC3339) DD/MM/YY or DD/MM/YYYY (deprecated) DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (deprecated)
int$gm1 =Input date is GM date, 0 =Input date is local date using PHP server timezone
Returns
int Date as a timestamp 19700101020000 -> 7200 with gm=1
See also
dol_print_date, dol_mktime, dol_getdate

Definition at line 286 of file date.lib.php.

References dol_mktime(), and dol_syslog().

Referenced by Tasks\addTimeSpent(), createInvoice(), createOrder(), createProject(), Dolistore\get_products(), CoreObject\setDate(), and ExportExcel\write_record().

dol_time_plus_duree (   $time,
  $duration_value,
  $duration_unit 
)

Add a delay to a date.

Parameters
int$timeDate timestamp (or string with format YYYY-MM-DD)
int$duration_valueValue of delay to add
int$duration_unitUnit of added delay (d, m, y, w, h)
Returns
int New timestamp

Definition at line 116 of file date.lib.php.

Referenced by modAdherent\__construct(), build_calfile(), Facture\create(), FactureRec\getNextDate(), box_activity\loadBox(), Project\loadTimeSpent(), num_public_holiday(), projectLinesPerWeek(), and Adherent\subscription().

get_tz_array ( )

Return an array with timezone values.

Returns
array Array with timezone values

Definition at line 33 of file date.lib.php.

getServerTimeZoneInt (   $refgmtdate = 'now')

Return server timezone int.

Parameters
string$refgmtdateReference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
Returns
int An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)

Definition at line 82 of file date.lib.php.

References dol_now(), dol_print_date(), dol_print_error(), and getServerTimeZoneString().

Referenced by dol_now(), dol_print_object_info(), and Form\select_date().

getServerTimeZoneString ( )

Return server timezone string.

Returns
string PHP server timezone string ('Europe/Paris')

Definition at line 71 of file date.lib.php.

Referenced by getServerTimeZoneInt().

monthArray (   $outputlangs,
  $short = 0 
)

Return array of translated months or selected month.

This replace old function monthArrayOrSelected.

Parameters
Translate$outputlangsObject langs
int$short1=Return short label
Returns
array Month string or array if selected < 0

Definition at line 907 of file date.lib.php.

Referenced by FormOther\select_month().

num_between_day (   $timestampStart,
  $timestampEnd,
  $lastday = 0 
)

Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 2012-01-02 => 1 if lastday=0, 2 if lastday=1.

Parameters
int$timestampStartTimestamp start UTC
int$timestampEndTimestamp end UTC
int$lastdayLast day is included, 0: no, 1:yes
Returns
int Number of days
See also
also num_public_holiday, num_open_day

Definition at line 833 of file date.lib.php.

Referenced by num_open_day().

num_open_day (   $timestampStart,
  $timestampEnd,
  $inhour = 0,
  $lastday = 0,
  $halfday = 0,
  $country_code = '' 
)

Function to return number of working days (and text of units) between two dates (working days)

Parameters
int$timestampStartTimestamp for start date (date must be UTC to avoid calculation errors)
int$timestampEndTimestamp for end date (date must be UTC to avoid calculation errors)
int$inhour0: return number of days, 1: return number of hours
int$lastdayWe include last day, 0: no, 1:yes
int$halfdayTag to define half day when holiday start and end
string$country_codeCountry code (company country code if not defined)
Returns
int Number of days or hours
See also
also num_between_day, num_public_holiday

Definition at line 863 of file date.lib.php.

References dol_syslog(), num_between_day(), and num_public_holiday().

num_public_holiday (   $timestampStart,
  $timestampEnd,
  $countrycode = 'FR',
  $lastday = 0 
)

Fonction retournant le nombre de jour feries, samedis et dimanches entre 2 dates entrees en timestamp.

Dates must be UTC with hour, day, min to 0 Called by function num_open_day

Parameters
int$timestampStartTimestamp de debut
int$timestampEndTimestamp de fin
string$countrycodeCountry code
int$lastdayLast day is included, 0: no, 1:yes
Returns
int Nombre de jours feries
See also
num_between_day, num_open_day

Definition at line 565 of file date.lib.php.

References dol_time_plus_duree().

Referenced by num_open_day().