Ticket #3 (new enhancement)

Opened 3 years ago

Last modified 2 years ago

Custom format_date() and format_time() function

Reported by: weppos Owned by:
Priority: normal Milestone: 2.2
Component: General Version: 2.1.4
Severity: normal Keywords:
Cc:

Description

Date and time must be filtered by those function before being displayed. These function take care of date and time conversion to a custom format and add timezone settings.

The admin panel must provide the following additional options

  • server to GMT time diff
  • GMT to (user) timezone time diff
  • (user) date time format

Change History

Changed 2 years ago by weppos

  • milestone changed from 2.1.x to 2.2

Changed 2 years ago by imente

some useful function to manage gtm dates (store & output)

'* #######################################
'* ##FUNC_INT##
'* @name		formatGMTDate
'* @version		1.0.0
'* @author		imente
'* @description
'*   formatta una data secondo un GMT
'* ---------------------------------------
'* @params
'*   argDate		DATE	la data da formattare
'*   argGMT			INT		il GMT da applicare
'* ---------------------------------------
'* @return
'* STR		la data formattata
'* @#####################################

function formatGMTDate(argDate, argGMT, argFormat)

	dim tmpdate,tmpdateoutput
	tmpdate = getGMTDate(argDate,argGMT)
	
	tmpdateoutput = argFormat
	
	tmpdateoutput = replace(tmpdateoutput,"ddd",left(weekdayname(weekday(tmpdate)),3))
	tmpdateoutput = replace(tmpdateoutput,"mmm",left(monthname(month(tmpdate)),3))
	
	tmpdateoutput = replace(tmpdateoutput,"dd",right("0" & day(tmpdate),2))
	tmpdateoutput = replace(tmpdateoutput,"mm",right("0" & month(tmpdate),2))
	tmpdateoutput = replace(tmpdateoutput,"yyyy",year(tmpdate))
	tmpdateoutput = replace(tmpdateoutput,"yy",right(year(tmpdate),2))
	
	tmpdateoutput = replace(tmpdateoutput,"hh",right("0" & hour(tmpdate),2))
	tmpdateoutput = replace(tmpdateoutput,"nn",right("0" & minute(tmpdate),2))
	tmpdateoutput = replace(tmpdateoutput,"ss",right("0" & second(tmpdate),2))
	
	formatGMTDate = tmpdateoutput

end function


'* #######################################
'* ##FUNC_INT##
'* @name		getGMTDate
'* @version		1.0.0
'* @author		imente
'* @description
'*   modifica una data applicandovi un GMT
'*  (sfasamento orario)
'* ---------------------------------------
'* @params
'*   argDate		DATE	la data da modificare
'*   argGMT			INT		il GMT da applicare
'* ---------------------------------------
'* @return
'* DATE		la data corretta
'* @#####################################

function getGMTDate(argDate,argGMT)

	getGMTDate = dateadd("h",argGMT,argDate)
	
end function

'* #######################################
'* ##FUNC_INT##
'* @name		formatHumanDate
'* @version		1.0.0
'* @author		imente
'* @description
'*   formatta una data secondo un GMT
'*	 se è recente la visualizza in formato
'*   leggibile più velocemente dall'uomo
'* ---------------------------------------
'* @params
'*   argDate		DATE	la data da formattare
'*   argGMT			INT		il GMT da applicare
'* ---------------------------------------
'* @return
'* STR		la data formattata
'* @#####################################

function formatHumanDate(argDate, argGMT,argFormat)

	dim tmpmdiff,tmphdiff,tmpdateoutput
	
	tmphdiff = int(datediff("n",argDate,now) / 60)
	if tmphdiff <= 6 then
		tmpmdiff = datediff("n",argDate,now)
		if tmpmdiff = 0 then
			tmpdateoutput = "meno di un minuto fa"
		elseif tmpmdiff <= 60 then
			tmpdateoutput = tmpmdiff & " minuti fa"
		elseif tmpmdiff mod 60 = 0 then
			tmpdateoutput = tmphdiff & " ore fa"
		else
			tmpdateoutput = tmphdiff & " ore e " & tmpmdiff mod 60 & " minuti fa"
		end if
	else
		tmpdateoutput = formatGMTDate(argDate,argGMT,argFormat)
	end if
	
	formatForumDate = tmpdateoutput

end function

'queste sono funzioni utili per salvare
'il valore GMT in un database in un campo
'di tipo byte unsigned

'* #######################################
'* ##FUNC_INT##
'* @name		formatGMT
'* @version		1.0.0
'* @author		imente
'* @description
'*   formatta un GMT da Unsigned a Signed
'* ---------------------------------------
'* @params
'*   argGMT		Byte	il gmt
'* ---------------------------------------
'* @return
'* Byte		il GMT formattato
'* @#####################################
function formatGMT(argGMT)

	if argGMT > 48 then argGmt = 48
	if argGMT < 0 then argGmt = 0
	if argGMT > 24 then
		formatGMT = 24 - argGMT
	else
		formatGMT = argGMT
	end if

end function

function unformatGMT(argGMT)

	if argGMT < 0 then
		unformatGMT = 24 + abs(argGMT)
	else
		unformatGMT = argGMT
	end if

end function
Note: See TracTickets for help on using tickets.