Calendar: Difference between revisions

Content added Content deleted
Line 1,787: Line 1,787:
exit(1);
exit(1);
}</syntaxhighlight>
}</syntaxhighlight>

{{libheader|Gadget}}
{{trans|Amazing Hopper}}
<syntaxhighlight lang="c">

#include <gadget/gadget.h>
LIB_GADGET_START

void draw_calendar( RDS(char*,calendario), int year );
void print_calendar( RDS(char*,calendario) );

Main
Assert( Arg_count ==2, fail_arg );
Get_arg_int( year, 1 );

ACTUAL_LANG_DATE = EN; /* text in english */
New array calendario as string;
/* get full year:
112 = code for months after initial month.
1 = initial month
year = well... */
calendario = Calendar(calendario, 112, 1, year);
draw_calendar( SDS(calendario), year );
Free str array calendario;
Exception( fail_arg ){
Msg_yellow("Modo de uso:\n ./calendar <nYear>");
}

End

void draw_calendar( RDS( char*, calendario), int year )
{
int fila=4, columna=1, cnt_columna=1, cnt_mes=0, i=0;
Cls;
At 2,35; Print "%d", year;

while ( cnt_mes < 12 )
{
String month_name;
Stack {
Store ( month_name, Pad_c( Capital( Get_monthname(cnt_mes++) ),' ',23) );
} Stack_off;
At fila, columna; Print "%s", month_name;

Atrow ++fila;
Range for calendario [ i+1: 1: i+8, 0:1: Cols(calendario) ];
print_calendar( SDS(calendario) );
--fila;
++cnt_columna;
columna += 25;
When( cnt_columna == 4 ) {
cnt_columna = columna = 1;
fila+=9;
}
i+=8;
Free secure month_name;
}
Prnl;
}


void print_calendar( RDS(char*,calendario) )
{
int i,j;
int row = SCREEN_ROW;

Iterup( row, calendario, i)
{
Iterup( col, calendario, j)
{
Print "%*s", 3, $calendario[i,j];
}
Atrow ++row;
}
}

</syntaxhighlight>
{{out}}
<pre>
1969

January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31

April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30

July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30
31

October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30

</pre>

=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
An attempt to abuse the DateTime class for all static information. In the event that the number of days and months changes, so long as the DateTime class is updated accordingly, this should still print properly. It also abuses iterators to allow for a concise month printing method, but with the ability to still print x months per line.
An attempt to abuse the DateTime class for all static information. In the event that the number of days and months changes, so long as the DateTime class is updated accordingly, this should still print properly. It also abuses iterators to allow for a concise month printing method, but with the ability to still print x months per line.