Page 1 of 1

FormatDate(Mask$, Date)

Posted: Wed May 18, 2011 4:50 pm
by IdeasVacuum
The Mask$ for date formats is really minimal - would be good to have Day and Month names (full and abbreviated).

Re: FormatDate(Mask$, Date)

Posted: Wed May 18, 2011 7:34 pm
by freak
In what language would you prefer the names? ;)

Re: FormatDate(Mask$, Date)

Posted: Wed May 18, 2011 9:11 pm
by IdeasVacuum
erm, how about Mongolian?

Re: FormatDate(Mask$, Date)

Posted: Wed May 18, 2011 9:32 pm
by ts-soft
freak wrote:In what language would you prefer the names? ;)
For the mask %month, %day and for the result the userlanguage, should not a big problem :wink:

Re: FormatDate(Mask$, Date)

Posted: Wed May 18, 2011 10:46 pm
by MachineCode
freak wrote:In what language would you prefer the names? ;)
GetLocaleInfo_(#LOCALE_USER_DEFAULT, ...)

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 8:31 am
by Trond
I don't like it, when applications in one language display shortcuts or dates in another language.

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 10:01 am
by STARGĂ…TE
here a small example, to use a macro like FormatDate():

Code: Select all

Procedure.s FormatDateEx(Mask.s, Date.l)
	Protected MonthName.s = Trim(PeekS(?FormatDateEx_MonthName+(Month(Date)-1)*8, 8))
	Protected DayOfWeekName.s = Trim(PeekS(?FormatDateEx_DayOfWeekName+DayOfWeek(Date)*9, 9))
	Mask = ReplaceString(Mask, "%month", MonthName, #PB_String_NoCase)
	Mask = ReplaceString(Mask, "%day", DayOfWeekName, #PB_String_NoCase)
	ProcedureReturn FormatDate(Mask, Date)
EndProcedure

Macro FormatDate(Mask, Date)
	FormatDateEx(Mask, Date)
EndMacro

DataSection
	FormatDateEx_DayOfWeekName:
	Data.s "Sunday   Monday   Tuesday  WednesdayThursday Friday   Saturday "
	FormatDateEx_MonthName:
	Data.s "January FebruaryMarch   April   May     June    July    August  SeptemberOctober NovemberDecember"
EndDataSection

Debug FormatDate("%day, %dd. %month %yyyy", Date())

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 2:48 pm
by Little John
It doesn't make sense to build anything and everything into PB. This concerns particularly stuff that we can easily write ourselves by using PB as it is.

Regards, Little John

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 3:01 pm
by IdeasVacuum
Little John wrote:It doesn't make sense to build anything and everything into PB. This concerns particularly stuff that we can easily write ourselves by using PB as it is.

Regards, Little John
Yeah, you are right. Not having needed it before, I was just surprised to find the function to be so limited. When you only have numbers in dates, people can get confused because of the format. 05/04/2011 is the 5th of April in the UK and other countries, but it's the 4th of May in many others.

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 3:07 pm
by MachineCode
Little John wrote:It doesn't make sense to build anything and everything into PB.
Sure it does! Fred did it all the time in the past. It's only in the past few years that responding to user requests slowed down, immensely. There was a time when little requests like this one were honored very quickly, but the language was much younger back then, so I guess it had to grow.

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 3:21 pm
by Little John
IdeasVacuum wrote:When you only have numbers in dates, people can get confused because of the format. 05/04/2011 is the 5th of April in the UK and other countries, but it's the 4th of May in many others.
I absolutely agree, and I'm aware of that problem.

It's just so easy to write a little function myself, that works exactly like I want. And someone else probably wants such a function to work a little differently, so s/he'll write a function that works exactly like s/he wants, etc. ... :-)

Regards, Little John

Re: FormatDate(Mask$, Date)

Posted: Thu May 19, 2011 5:53 pm
by freak
Internationalization is one of the hardest things to get absolutely right. I really don't want to open that can of worms for such a small issue.