[Include] Days [BETA]
#1

Days

No known bugs as of now, although if you find some, report them

IF no bugs are found, next update will be in July.


pawn Код:
#define     JANUARY     1
#define     FEBRUARY    2
#define     MARCH       3
#define     APRIL       4
#define     MAY         5
#define     JUNE        6
#define     JULY        7
#define     AUGUST      8
#define     SEPTEMBER   9
#define     OCTOBER     10
#define     NOVEMBER    11
#define     DECEMBER    12

#define     MONDAY          0
#define     TUESDAY         1
#define     WEDNESDAY       2
#define     THURSDAY        3
#define     FRIDAY      4
#define     SATURDAY        5
#define     SUNDAY      6

pawn Код:
native GetMonthName(month); //number of month OR the NAME of the month in CAPITAL LETTERS
native GetDayName(day); // NUMBER of DAY or name of DAY in CAPITAL letters [0 TO 6]
native GetCurrentMonth(); // returns the current month
native GetCurrentDay(); // returns the current DATE
native IsLeapYear(year); // returns if the INPUT YEAR is a LEAP YEAR
native GetMonthDays(month); // RETURNS THE NUMBER OF DAYS OF THE INPUT MONTH
native GetDay(date, month, year); // returns the >> DAY << (NOT DATE)

BETA V1 - http://pastebin.com/9tH7Bkqp


Test code -

pawn Код:
main()
{
    printf("%s", GetDayName(GetDay(15, JULY, 2013)) );
}
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
There are ways of working out what day any date in history was - programs don't store big lists they just work it out on the fly.
I know this is not the best way, it's just an alternate till I find a way to get the exact day when provided the date.
and I'm not really familiar with PHP or HTML, so, if you can suggest a better method, it'll be much appreciated.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
I found these: http://www.wikihow.com/Calculate-the-Day-of-the-Week they're written for mental calculation, but I'm sure there are ways to port them to code. I also found this JavaScript, but again don't know how reliable it is:

http://www.sislands.com/coin70/week3/dayofwk.htm

A cursory glance looks OK, and don't forget that PAWN already has integer division represented in that code by Math.floor.
Glad you gave me those links, took me a while but I finally converted them!

pawn Код:
stock GetDay(day, month, year)
{
    if (month < 3)
    {
        month += 12;
        year--;
    }
    return ((13*month+3)/5 + day + year + year/4 - year/100 + year/400) % 7;
}
Updating the post now.
Reply
#4

Hmm.. What's the sole(or main, or however you describe it) function of this include? Maybe I can get this, but what about the other beginners who can't get this?
Reply
#5

Quote:
Originally Posted by Dzines4SAMP
Посмотреть сообщение
Hmm.. What's the sole(or main, or however you describe it) function of this include? Maybe I can get this, but what about the other beginners who can't get this?
It can be used for many things!
The day on which the player registered,
Can be used as an extra param in TIMESTAMP's

Use your imagination, there are endless possibilities if you really want to use the functions.

I use this in my server for -

Getting the day on which the server registered (provided I save the date,month,year)
Getting the day on which the player was banned/will be unbanned [provided the date,month,year]
Setting up a local-server clock

@****** - thanks for pointing that out, updated the define's, any idea what I should replace % 7 with so that I can use numbers 1 to 7?
Reply
#6

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
It can be used for many things!
The day on which the player registered,
Can be used as an extra param in TIMESTAMP's

Use your imagination, there are endless possibilities if you really want to use the functions.

I use this in my server for -

Getting the day on which the server registered (provided I save the date,month,year)
Getting the day on which the player was banned/will be unbanned [provided the date,month,year]
Setting up a local-server clock

@****** - thanks for pointing that out, updated the define's, any idea what I should replace % 7 with so that I can use numbers 1 to 7?
(x % 7) + 1
Reply
#7

How i see in-game what day it is?
And about :
Quote:

pawn Code:

main()
{
printf("%s", GetDayName(GetDay(15, JULY, 2013)) );
}
Give me that errors:
....: error 029: invalid expression, assumed zero
.... : error 017: undefined symbol "x"
... : warning 215: expression has no effect
... : warning 209: function "GetDay" should return a value
... : error 021: symbol already defined: "main"
A command like /calendar ...would be useful... ( if you have time,can tell me how to do that please? )
Question:After that , the time is 1 minute=60 seconds,i want to be 1 minute=1 second ,what i have to change?

I'm begginer,so i ask what i don't understand,i hope that don't upset you.
Reply
#8

Quote:
Originally Posted by Badarau
Посмотреть сообщение
How i see in-game what day it is?
And about :
Give me that errors:
....: error 029: invalid expression, assumed zero
.... : error 017: undefined symbol "x"
... : warning 215: expression has no effect
... : warning 209: function "GetDay" should return a value
... : error 021: symbol already defined: "main"
A command like /calendar ...would be useful... ( if you have time,can tell me how to do that please? )
Question:After that , the time is 1 minute=60 seconds,i want to be 1 minute=1 second ,what i have to change?

I'm begginer,so i ask what i don't understand,i hope that don't upset you.
Those errors are your code problem, and

for @Function "GetDay" should return a value, I just checked, here's the function
pawn Код:
stock GetDay(day, month, year)
{
    if (month < 3)
    {
        month += 12;
        year--;
    }
    return ((13*month+3)/5 + day + year + year/4 - year/100 + year/400) % 7;
}
It DOES return a value, and it seems to work for my gamemode.

Rest are your personal errors.

And how to make calendar, I have no idea, I don't know if the standard way



is possible in SA-MP.
Reply
#9

Yea,like the classic calendar...if is possible...in a window,and at every 24:00 + the calendar appear and show you what date is.
Question:How i return the time at 1 minute = 1 second ?
Reply
#10

Quote:
Originally Posted by Badarau
Посмотреть сообщение
How i see in-game what day it is?
And about :
Give me that errors:
....: error 029: invalid expression, assumed zero
.... : error 017: undefined symbol "x"
... : warning 215: expression has no effect
... : warning 209: function "GetDay" should return a value
... : error 021: symbol already defined: "main"
A command like /calendar ...would be useful... ( if you have time,can tell me how to do that please? )
Question:After that , the time is 1 minute=60 seconds,i want to be 1 minute=1 second ,what i have to change?

I'm begginer,so i ask what i don't understand,i hope that don't upset you.
Код:
stock GetDay(day, month, year)
{
    if (month < 3)
    {
        month += 12;
        year--;
    }
    return ((13*month+3)/5 + day + year + year/4 - year/100 + year/400) % 7;
}
Reply
#11

Correction...

pawn Код:
stock IsLeapYear(year)
{
    if(year % 4 == 0)
    {
        if(year % 100 == 0 && year % 400 != 0) return 0;
        else return 1;
    }
    else return 0;
}
Reply
#12

Quote:
Originally Posted by Dragony92
Посмотреть сообщение
Correction...

pawn Код:
stock IsLeapYear(year)
{
    if(year % 4 == 0)
    {
        if(year % 100 == 0 && year % 400 != 0) return 0;
        else return 1;
    }
    else return 0;
}
Can you explain how that's different/more efficient/how does the existing system NOT work properly?
Reply
#13

http://en.wikipedia.org/wiki/Leap_year
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)