dolibarr 21.0.0-beta
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.
 
 getServerTimeZoneString ()
 Return server timezone string.
 
 getServerTimeZoneInt ($refgmtdate='now')
 Return server timezone int.
 
 dol_time_plus_duree ($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
 Add a delay to a date.
 
 convertTime2Seconds ($iHours=0, $iMinutes=0, $iSeconds=0)
 Convert hours and minutes into seconds.
 
 convertSecondToTime ($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
 Return, in clear text, value of a number of seconds in days, hours and minutes.
 
 convertDurationtoHour ($duration_value, $duration_unit)
 Convert duration to hour.
 
 dolSqlDateFilter ($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
 Generate a SQL string to make a filter into a range (for second of date until last second of date).
 
 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.
 
 dol_get_prev_day ($day, $month, $year)
 Return previous day.
 
 dol_get_next_day ($day, $month, $year)
 Return next day.
 
 dol_get_prev_month ($month, $year)
 Return previous month.
 
 dol_get_next_month ($month, $year)
 Return next month.
 
 dol_get_prev_week ($day, $week, $month, $year)
 Return previous week.
 
 dol_get_next_week ($day, $week, $month, $year)
 Return next week.
 
 dol_get_first_day ($year, $month=1, $gm=false)
 Return GMT time for first day of a month or year.
 
 dol_get_last_day ($year, $month=12, $gm=false)
 Return GMT time for last day of a month or year.
 
 dol_get_last_hour ($date, $gm='tzserver')
 Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59)
 
 dol_get_first_hour ($date, $gm='tzserver')
 Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
 
 dol_get_first_day_week ($day, $month, $year, $gm=false)
 Return first day of week for a date.
 
 getGMTEasterDatetime ($year)
 Return the easter day in GMT time.
 
 num_public_holiday ($timestampStart, $timestampEnd, $country_code='', $lastday=0, $includesaturday=-1, $includesunday=-1, $includefriday=-1, $includemonday=-1)
 Return the number of non working days including Friday, Saturday and Sunday (or not) between 2 dates in timestamp.
 
 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.
 
 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)
 
 monthArray ($outputlangs, $short=0)
 Return array of translated months or selected month.
 
 getWeekNumbersOfMonth ($month, $year)
 Return array of week numbers.
 
 getFirstDayOfEachWeek ($TWeek, $year)
 Return array of first day of weeks.
 
 getLastDayOfEachWeek ($TWeek, $year)
 Return array of last day of weeks.
 
 getWeekNumber ($day, $month, $year)
 Return week number.
 

Detailed Description

Set of function to manipulate dates.

Definition in file date.lib.php.

Function Documentation

◆ convertDurationtoHour()

convertDurationtoHour ( $duration_value,
$duration_unit )

Convert duration to hour.

Parameters
float$duration_valueDuration value
string$duration_unitDuration unit
Returns
float $result
See also
measuringUnitString()

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

Referenced by BOM\calculateCosts().

◆ convertSecondToTime()

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
'all'|'allwithouthour'|'allhourmin'|'allhourminsec'|'allhour'|'fullhour'|'hour'|'min'|'sec'|'month'|'year'$format Output 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",
  • 'allhourminsec': total delay with format hours:min:sec like "60:30:10",
  • '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<1,86400>$lengthOfDay Length of day (default 86400 seconds for 1 day, 28800 for 8 hour)
int<1,7>$lengthOfWeek Length of week (default 7)
Returns
string Formatted 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 244 of file date.lib.php.

References dol_print_date().

Referenced by build_calfile(), constructGanttLine(), doc_generic_project_odt\get_substitutionarray_tasks(), doc_generic_task_odt\get_substitutionarray_tasks(), doc_generic_project_odt\get_substitutionarray_taskstime(), doc_generic_task_odt\get_substitutionarray_taskstime(), Fichinter\getKanbanView(), getTaskProgressView(), print_projecttasks_array(), projectLinesa(), projectLinesPerAction(), projectLinesPerDay(), projectLinesPerWeek(), ExtraFields\showOutputField(), FormWebPortal\showOutputFieldForObject(), pdf_baleine\write_file(), pdf_soleil\write_file(), pdf_strato\write_file(), and pdf_timespent\write_file().

◆ convertTime2Seconds()

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 215 of file date.lib.php.

◆ dol_get_first_day()

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
bool | int | string$gmFalse or 0 or 'tzserver' = Return date to compare with server TZ, True or 1 or 'gmt' to compare with GMT date. Example: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00 Example: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
Returns
int|string Date as a timestamp, '' if error

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

References dol_mktime().

Referenced by pdf_standard_actions\_pages(), activitytrim(), ActionComm\build_exportfile(), ProjectStats\buildWhere(), TaskStats\buildWhere(), Asset\calculationDepreciation(), AdherentStats\countMembersByTagAndStatus(), AdherentStats\countMembersByTypeAndStatus(), Facture\createFromClone(), dolSqlDateFilter(), CommandeStats\getAllByProduct(), FactureStats\getAllByProduct(), FichinterStats\getAllByProduct(), PropaleStats\getAllByProduct(), CommandeStats\getAmountByMonth(), FactureStats\getAmountByMonth(), FichinterStats\getAmountByMonth(), PropaleStats\getAmountByMonth(), ReceptionStats\getAmountByMonth(), FactureStats\getAmountByYear(), CommandeStats\getAverageByMonth(), FactureStats\getAverageByMonth(), FichinterStats\getAverageByMonth(), ProjectStats\getAverageByMonth(), PropaleStats\getAverageByMonth(), ReceptionStats\getAverageByMonth(), TaskStats\getAverageByMonth(), CommandeStats\getNbByMonth(), DonationStats\getNbByMonth(), ExpeditionStats\getNbByMonth(), FactureStats\getNbByMonth(), FichinterStats\getNbByMonth(), PropaleStats\getNbByMonth(), ReceptionStats\getNbByMonth(), AccountancyCategory\getSumDebitCredit(), box_birthdays\loadBox(), Localtax\localtax_sum_collectee(), Localtax\localtax_sum_payee(), Localtax\localtax_sum_reglee(), tax_by_rate(), tax_by_thirdparty(), pdf_paiement\write_file(), and pdf_standard_movementstock\write_file().

◆ dol_get_first_day_week()

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
bool|int|'tzserver'$gm False or 0 or 'tzserver' = Return date to compare with server TZ, True or 1 or 'gmt' to compare with GMT date.
Returns
array{year:int,month:int,week:string,first_day:int,first_month:int,first_year:int,prev_year:int,prev_month:int,prev_day:int}

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

References $conf, dol_getdate(), and dol_mktime().

Referenced by Project\createWeeklyReport(), dol_get_next_week(), and dol_get_prev_week().

◆ dol_get_first_hour()

dol_get_first_hour ( $date,
$gm = 'tzserver' )

Return GMT time for first hour of a given GMT date (it removes hours, min and second part)

Parameters
int$dateDate GMT
bool | int | string$gmFalse or 0 or 'tzserver' = Return date to compare with server TZ, 'gmt' to compare with GMT date.
Returns
int Date for first hour of a given date

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

References dol_getdate(), and dol_mktime().

Referenced by User\isNotIntoValidityDateRange(), Facture\sendEmailsRemindersOnInvoiceDueDate(), and FactureFournisseur\sendEmailsRemindersOnSupplierInvoiceDueDate().

◆ dol_get_last_day()

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

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

Note: The timestamp contains last day and last hours (23:59:59)

Parameters
int$yearYear
int$monthMonth
bool | int | string$gmFalse or 0 or 'tzserver' = Return date to compare with server TZ, True or 1 or 'gmt' to compare with GMT date.
Returns
int|string Date as a timestamp, '' if error

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

References dol_mktime().

Referenced by pdf_standard_actions\_pages(), ActionComm\build_exportfile(), ProjectStats\buildWhere(), TaskStats\buildWhere(), Asset\calculationDepreciation(), Facture\createFromClone(), dolSqlDateFilter(), Accountancy\exportData(), CommandeStats\getAllByProduct(), FactureStats\getAllByProduct(), FichinterStats\getAllByProduct(), PropaleStats\getAllByProduct(), CommandeStats\getAmountByMonth(), FactureStats\getAmountByMonth(), FichinterStats\getAmountByMonth(), PropaleStats\getAmountByMonth(), ReceptionStats\getAmountByMonth(), FactureStats\getAmountByYear(), CommandeStats\getAverageByMonth(), FactureStats\getAverageByMonth(), FichinterStats\getAverageByMonth(), ProjectStats\getAverageByMonth(), PropaleStats\getAverageByMonth(), ReceptionStats\getAverageByMonth(), TaskStats\getAverageByMonth(), getCurrentPeriodOfFiscalYear(), getDefaultDatesForTransfer(), CommandeStats\getNbByMonth(), DonationStats\getNbByMonth(), ExpeditionStats\getNbByMonth(), FactureStats\getNbByMonth(), FichinterStats\getNbByMonth(), PropaleStats\getNbByMonth(), ReceptionStats\getNbByMonth(), AccountancyCategory\getSumDebitCredit(), Localtax\localtax_sum_collectee(), Localtax\localtax_sum_payee(), Localtax\localtax_sum_reglee(), tax_by_rate(), tax_by_thirdparty(), pdf_paiement\write_file(), and pdf_standard_movementstock\write_file().

◆ dol_get_last_hour()

dol_get_last_hour ( $date,
$gm = 'tzserver' )

Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59)

Parameters
int$dateDate GMT
bool | int | string$gmFalse or 0 or 'tzserver' = Return date to compare with server TZ, 'gmt' to compare with GMT date.
Returns
int Date for last hour of a given date

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

References dol_getdate(), and dol_mktime().

Referenced by Facture\createDepositFromOrigin(), getCurrentPeriodOfFiscalYear(), and User\isNotIntoValidityDateRange().

◆ dol_get_next_day()

dol_get_next_day ( $day,
$month,
$year )

Return next day.

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

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

References dol_getdate(), and dol_mktime().

◆ dol_get_next_month()

dol_get_next_month ( $month,
$year )

Return next month.

Parameters
int$monthMonth
int$yearYear
Returns
array{year:int,month:int} Next year,month

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

Referenced by Facture\createFromClone(), and Holiday\updateSoldeCP().

◆ dol_get_next_week()

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

Return next week.

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

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

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

◆ dol_get_prev_day()

dol_get_prev_day ( $day,
$month,
$year )

Return previous day.

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

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

References dol_getdate(), and dol_mktime().

◆ dol_get_prev_month()

dol_get_prev_month ( $month,
$year )

Return previous month.

Parameters
int$monthMonth
int$yearYear
Returns
array{year:int,month:int} Previous year,month

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

Referenced by Accountancy\exportData().

◆ dol_get_prev_week()

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

Return previous week.

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

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

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

◆ dol_stringtotime()

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 | string$gm'gmt' or 1 =Input date is GM date, 'tzserver' or 0 =Input date is date using PHP server timezone
Returns
int Date as a timestamp 19700101020000 -> 7200 with gm=1 19700101000000 -> 0 with gm=1
See also
dol_print_date(), dol_mktime(), dol_getdate()

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

References dol_mktime(), and dol_syslog().

Referenced by Invoices\addPayment(), Invoices\addPaymentDistributed(), Tasks\addTimeSpent(), ActionComm\build_exportfile(), Export\build_file(), createInvoice(), createOrder(), createProject(), Dolistore\get_products(), ImportCsv\import_insert(), ImportXlsx\import_insert(), StockMovements\post(), Tasks\putTimeSpent(), Holiday\updateSoldeCP(), and ExportExcel2007\write_record().

◆ dol_time_plus_duree()

dol_time_plus_duree ( $time,
$duration_value,
$duration_unit,
$ruleforendofmonth = 0 )

◆ dolSqlDateFilter()

dolSqlDateFilter ( $datefield,
$day_date,
$month_date,
$year_date,
$excludefirstand = 0,
$gm = false )

Generate a SQL string to make a filter into a range (for second of date until last second of date).

This method allows to maje SQL request that will deal correctly the timezone of server.

Parameters
string$datefieldName of SQL field where apply sql date filter
int | string$day_dateDay date (Can be 0 or '' for filter on a month)
int | string$month_dateMonth date (Can be 0 or '' for filter on a year)
int | string$year_dateYear date
int$excludefirstandExclude first and
mixed$gmFalse or 0 or 'tzserver' = Input date fields are date info in the server TZ. True or 1 or 'gmt' = Input are date info in GMT TZ. Note: In database, dates are always for the server TZ.
Returns
string $sqldate String with SQL filter
See also
forgeSQLFromUniversalSearchCriteria()
natural_search()

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

References dol_get_first_day(), dol_get_last_day(), and dol_mktime().

Referenced by BookKeeping\deleteByYearAndJournal(), box_birthdays\loadBox(), and box_birthdays_members\loadBox().

◆ get_tz_array()

get_tz_array ( )

Return an array with timezone values.

Returns
array<int<-11,13>,string> Array with timezone values

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

◆ getFirstDayOfEachWeek()

getFirstDayOfEachWeek ( $TWeek,
$year )

Return array of first day of weeks.

Parameters
string[]$TWeekarray of week numbers we want (week 1 must be '01')
int$yearYear number
Returns
string[] First day of each week in entry (day 1 is '01')

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

◆ getGMTEasterDatetime()

getGMTEasterDatetime ( $year)

Return the easter day in GMT time.

This function replaces easter_date() that returns a date in local TZ.

Parameters
int$yearYear
Returns
int GMT Date of easter day

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

Referenced by num_public_holiday().

◆ getLastDayOfEachWeek()

getLastDayOfEachWeek ( $TWeek,
$year )

Return array of last day of weeks.

Parameters
string[]$TWeekarray of week numbers
int$yearYear number
Returns
string[] Last day of week (day 1 is '01')

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

◆ getServerTimeZoneInt()

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
float An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer). Note some countries use half and even quarter hours.

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

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

Referenced by dol_print_object_info(), and Form\selectDate().

◆ getServerTimeZoneString()

getServerTimeZoneString ( )

Return server timezone string.

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

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

Referenced by getServerTimeZoneInt().

◆ getWeekNumber()

getWeekNumber ( $day,
$month,
$year )

Return week number.

Parameters
int$dayDay number
int$monthMonth number
int$yearYear number
Returns
string Week number as two digits (week 1 is '01')

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

Referenced by getWeekNumbersOfMonth(), and Project\loadTimeSpentMonth().

◆ getWeekNumbersOfMonth()

getWeekNumbersOfMonth ( $month,
$year )

Return array of week numbers.

Parameters
int$monthMonth number
int$yearYear number
Returns
string[] Week numbers (week 1 is '01')

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

References getWeekNumber().

◆ monthArray()

monthArray ( $outputlangs,
$short = 0 )

Return array of translated months or selected month.

This replace old function monthArrayOrSelected.

Parameters
Translate$outputlangsObject langs
int$short0=Return long label, 1=Return short label
Returns
array<int<1,12>,string> String of months in normal or short string format

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

◆ num_between_day()

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
num_public_holiday(), num_open_day()

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

Referenced by Asset\calculationDepreciation(), and num_open_day().

◆ 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|string Number of days or hours or string if error @seealso num_between_day(), num_public_holiday()

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

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

Referenced by Export\build_file(), sendMail(), and Holiday\updateSoldeCP().

◆ num_public_holiday()

num_public_holiday ( $timestampStart,
$timestampEnd,
$country_code = '',
$lastday = 0,
$includesaturday = -1,
$includesunday = -1,
$includefriday = -1,
$includemonday = -1 )

Return the number of non working days including Friday, Saturday and Sunday (or not) between 2 dates in timestamp.

Dates must be UTC with hour, min, sec to 0. Called by function num_open_day()

Parameters
int$timestampStartTimestamp start (UTC with hour, min, sec = 0)
int$timestampEndTimestamp end (UTC with hour, min, sec = 0)
string$country_codeCountry code
int$lastdayLast day is included, 0: no, 1:yes
int$includesaturdayInclude saturday as non working day (-1=use setup, 0=no, 1=yes)
int$includesundayInclude sunday as non working day (-1=use setup, 0=no, 1=yes)
int$includefridayInclude friday as non working day (-1=use setup, 0=no, 1=yes)
int$includemondayInclude monday as non working day (-1=use setup, 0=no, 1=yes)
Returns
int|string Number of non working days or error message string if error
See also
num_between_day(), num_open_day()

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

References $conf, dol_getIdFromCode(), dol_syslog(), dol_time_plus_duree(), getDolGlobalInt(), and getGMTEasterDatetime().

Referenced by Project\createWeeklyReport(), and num_open_day().