FormatDate(Mask$, Date)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

FormatDate(Mask$, Date)

Post by IdeasVacuum »

The Mask$ for date formats is really minimal - would be good to have Day and Month names (full and abbreviated).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: FormatDate(Mask$, Date)

Post by freak »

In what language would you prefer the names? ;)
quidquid Latine dictum sit altum videtur
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FormatDate(Mask$, Date)

Post by IdeasVacuum »

erm, how about Mongolian?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FormatDate(Mask$, Date)

Post 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:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: FormatDate(Mask$, Date)

Post by MachineCode »

freak wrote:In what language would you prefer the names? ;)
GetLocaleInfo_(#LOCALE_USER_DEFAULT, ...)
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: FormatDate(Mask$, Date)

Post by Trond »

I don't like it, when applications in one language display shortcuts or dates in another language.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: FormatDate(Mask$, Date)

Post 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())
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: FormatDate(Mask$, Date)

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FormatDate(Mask$, Date)

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: FormatDate(Mask$, Date)

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: FormatDate(Mask$, Date)

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: FormatDate(Mask$, Date)

Post 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.
quidquid Latine dictum sit altum videtur
Post Reply