HI, I have DAY MONTH and YEAR and want to create the date string using Locale format, so it shows the correct separator character ('-' '.' '/' ...) for the language being used under AmigaOS4.
What I'm doing now is to "get" such date separator char by "parsing" 'loc_ShortDateFormat' (locale.h)
struct Locale *ll = ILocale->OpenLocale(NULL); char DateSep = *(ll->loc_ShortDateFormat+IUtility->Strlen(ll->loc_ShortDateFormat)-3); IDOS->Printf("\n'%lc'\n", DateSep);
Is there a proper/nice way to get such date separator character, or to build the date string, something like:
DateString_res = ILocale->BuildDateString(Locale, ShortDateMode, Day,Month,Year)
TIA
@jabiluro
Check the DateToStr() function in the DOS autodocs. It seems to offer a number of date format options.
X1000 - OS 4.1FE
@jabirulo
IDOS->DateToStr() with dat_Format set to FORMAT_DEF should format according to the current system default locale.
Both IDOS->DateToStr and ILocale->FormatDate should do. But there is no way to get a proper date from day/month/year, you rather need the number of days since 1978.
IUtility->Date2Amiga() can be used to convert day/month/year to the total number of seconds since 1.1.1978 and IDOS->SecondsToDateStamp() can then be used to convert this to a struct DateStamp for IDOS->DateToStr().
@jabirulo
Assuming your "Day,Month,Year" are numbers it might be simpler to use something like this:
X1000 - OS 4.1FE
THX guays for all suggestions will try'em ASAP.
Again, thx for all.
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Just started to implement using Xenic's code (after that will use other's code posted)
I get:
xadUnFileS.c: In function 'DateLocalized':
xadUnFileS.c:848: warning: function returns address of local variable
Am I missing some cast or am I doing coding it very bad?
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
@jabirulo
You made a mistake. The "res_buf" variable is declared within the DateLocalized() function and is 'local' to that function. When you exit the DateLocalized() function, all local variables declared within the function are gone and no longer valid or legally accessible.
X1000 - OS 4.1FE
@jabirulo
I also noticed that you commented out the DateTime structure initialization. If you don't initialize the DateTime structure you will probably get the wrong date result. Leave it like this:
struct DateTime dt = {{0}}; or struct DateTime = {{0},0};
X1000 - OS 4.1FE
Yes, you're right I was testing and found that dates were random :-P restored initialization.
Changed to "void DateLocalized(struct xadDate *pXadDate, STRPTR dest)"
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
Using the method I suggested:
IMO it is more elegant than using a string as an intermediate format and it can easily be extended to obtain a formatted time string as well.
The wday field of the ClockData structure is not used by Date2Amiga() at all so it can be left as undefined if wanted. I just set it here for no real reason.
Also if formatted time is not needed the sec, min and hour fields can be set to zero.
THX. I created that one, and will updated with your psoted code (and was thinking to add time too).
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
and here is mrirtter version:
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
@jabirulo
I haven't had time to test it but here is another possibility based on your code:
X1000 - OS 4.1FE