Quote:
Originally Posted by Natsheh
Bugsy the format you made it converts only weeks in numbers i think he wants to be able also to convert weeks in thier name form.
I can make you a simple stock so it can format any type of time formats but you need to wait until i come back to home.
|
I can easily do that too, but I don't think your assumption is true. He is retrieving the weekday name using get_time( "%A" ) and then passing that to CalculateDays(const szDay[]) to get the numerical day-of-week value, he should have instead used "%w", as my code does, as it eliminates the need for his CalculateDays() function.
Code:
%A Full weekday name * Thursday
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
This is why I asked for a verbal explanation as without a specific use-case, we have to make assumptions. He advised to refer to post 3, which is what I based my code off of:
"Thanks for taking the time to respond, the "problem" is that I want this automated
function to run on a specific day and time every week, for example every Saturday 12 PM, which is why parse_time doesn't seem to cover this situation."
Code:
public CalculateStrings
()
{
new Time[15], ToDay
[5], Month
[5]
//%A - Full weekday name * Thursday
get_time("%A", Time, charsmax(Time))
new EventDay = 7 - CalculateDays(Time)
get_time("%d", ToDay, charsmax
(ToDay
))
new iFutureDate =
str_to_num(ToDay
) + EventDay
get_time("%m", Month, charsmax
(Month
))
new FormatedFutureDate
[30]
formatex
(FormatedFutureDate, charsmax
(FormatedFutureDate
),
"19:00:00 %i/%i/2021",
str_to_num(Month
), iFutureDate
)
new iFutureDateTime =
parse_time( FormatedFutureDate ,
"%H:%M:%S %m/%d/%Y" );
new iCurrentDateTime =
get_systime();
Counter = iFutureDateTime - iCurrentDateTime;
set_task_ex
(1.0,
"TimeToEvent", TASK_HUD_DROP, .
flags = SetTask_Repeat
)
}
convert_seconds
( iTotalSeconds , &seconds , &minutes , &hours , &days
)
{
days = iTotalSeconds /
86400
hours =
( iTotalSeconds /
3600 ) %
24
minutes =
( iTotalSeconds /
60 ) %
60
seconds = iTotalSeconds %
60
}
CalculateDays
(const szDay
[])
{
new Count =
0
enum _:ItemData
{
szDays
[10],
iCount
}
new const g_szDays
[][ItemData
] =
{
{"Sunday",
1},
{"Monday",
2},
{"Tuesday",
3},
{"Wednesday",
4},
{"Thursday",
5},
{"Friday",
6},
{"Saturday",
7}
}
for(new i; i < sizeof g_szDays; i++
)
{
if(equali(szDay, g_szDays[i][szDays]))
{
Count = g_szDays[i][iCount]
break
}
}
return Count
}
__________________