Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Date-manipulation/C/date-manipulation-1.c
Normal file
19
Task/Date-manipulation/C/date-manipulation-1.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
struct tm ts;
|
||||
time_t t;
|
||||
const char *d = "March 7 2009 7:30pm EST";
|
||||
|
||||
strptime(d, "%B %d %Y %I:%M%p %Z", &ts);
|
||||
/* ts.tm_hour += 12; instead of t += 12*60*60
|
||||
works too. */
|
||||
t = mktime(&ts);
|
||||
t += 12*60*60;
|
||||
printf("%s", ctime(&t));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
39
Task/Date-manipulation/C/date-manipulation-2.c
Normal file
39
Task/Date-manipulation/C/date-manipulation-2.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include <gadget/gadget.h>
|
||||
|
||||
LIB_GADGET_START
|
||||
|
||||
void write_human_date( const char* date, const char * time )
|
||||
{
|
||||
Print "%s %d %d %d:%d%s EST\n", Get_monthname( Get_month( date )-1 ),\
|
||||
Get_day( date ), Get_year( date ), \
|
||||
Get_hour(time),Get_minute(time), \
|
||||
Get_hour(time)>12 ? "pm" : "am" ;
|
||||
}
|
||||
|
||||
#define Sign(_N_) ( (_N_)<0? -1 : 1 )
|
||||
|
||||
Main
|
||||
Assert( Arg_count==2, fail_input );
|
||||
Get_arg_int( addhour, 1 );
|
||||
|
||||
Set_date_lang( EN ); // fix english language
|
||||
|
||||
char * date = Get_date();
|
||||
char * time = Get_time();
|
||||
addhour = Sign( addhour )*addhour;
|
||||
|
||||
write_human_date(date, time);
|
||||
|
||||
int adddays = ( Time2sec(time) + addhour*60*60 ) / 86400;
|
||||
Get_fn_let( time, Sec2time( (Time2sec(time) + addhour*60*60 )) );
|
||||
Get_fn_let( date, Date_add( date, adddays ) );
|
||||
|
||||
write_human_date(date, time);
|
||||
|
||||
Free secure date, time;
|
||||
|
||||
Exception( fail_input ){
|
||||
Msg_red("Use:\n addhour <nHours>\n")
|
||||
}
|
||||
|
||||
End
|
||||
87
Task/Date-manipulation/C/date-manipulation-3.c
Normal file
87
Task/Date-manipulation/C/date-manipulation-3.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include <gadget/gadget.h>
|
||||
|
||||
LIB_GADGET_START
|
||||
|
||||
void write_human_date( const char* date, const char * time )
|
||||
{
|
||||
Print "%s %d %d %d:%d%s EST\n", Get_monthname( Get_month( date )-1 ),\
|
||||
Get_day( date ), Get_year( date ), \
|
||||
Get_hour(time),Get_minute(time), \
|
||||
Get_hour(time)>=12 ? "pm" : "am" ;
|
||||
}
|
||||
|
||||
Main
|
||||
Assert( Arg_count==2, fail_input );
|
||||
Get_arg_str( cTime, 1 );
|
||||
int addhour;
|
||||
|
||||
if ( Occurs(":", cTime) ){ // input: hh:mm:ss"
|
||||
int sign = 1;
|
||||
if ( cTime[0] == '-' ) {
|
||||
sign=-1;
|
||||
Fn_let( cTime, Substr( cTime,Str_at("-",cTime)+1,strlen(cTime) ) );
|
||||
}
|
||||
|
||||
Assert ( Is_time_valid( cTime ), fail_time );
|
||||
|
||||
addhour = Time2sec( cTime ) * sign;
|
||||
|
||||
}else if( Occurs(",", cTime) ){ // horas>24 , minutos [0->59]
|
||||
long min=0;
|
||||
Stack{
|
||||
addhour = Str2int( Get_token(cTime,1) );
|
||||
min = Time2sec( Multi_copy( NULL, "00:", Get_token(cTime,2),NULL) );
|
||||
}Stack_off;
|
||||
if( addhour<0 ) {
|
||||
addhour = addhour*60*60 - min;
|
||||
}else{
|
||||
addhour = addhour*60*60 + min;
|
||||
}
|
||||
}else{
|
||||
addhour = Time2sec( cTime ); // asume hora simple
|
||||
}
|
||||
|
||||
Free secure cTime;
|
||||
|
||||
Set_date_lang( EN ); // fix english language
|
||||
|
||||
char * date = Get_date();
|
||||
char * time = Get_time();
|
||||
|
||||
int SGN = Sign(addhour);
|
||||
|
||||
write_human_date(date, time);
|
||||
int adddays=0;
|
||||
if( Is_non_neg(addhour) ){
|
||||
adddays = ( Time2sec(time) + addhour ) / 86400;
|
||||
Get_fn_let( time, Sec2time( (Time2sec(time) + addhour )) );
|
||||
Get_fn_let( date, Date_add( date, adddays ) );
|
||||
}else{
|
||||
int ts = Time2sec(time), nt = addhour;
|
||||
int subdays = ( Time2sec(time) + SGN*addhour ) / 86400;
|
||||
if( SGN*nt > ts ){
|
||||
Fn_let( time, Sec2time( 86400*subdays - SGN * (Time2sec(time) + addhour )) );
|
||||
}else{
|
||||
if( SGN*addhour/60/60 <= Get_hour(time) && Is_non_zero(subdays) )
|
||||
subdays--;
|
||||
Fn_let( time, Sec2time( (Time2sec(time) + addhour )) );
|
||||
}
|
||||
Get_fn_let( date, Date_add( date, SGN*subdays ) );
|
||||
}
|
||||
write_human_date(date, time);
|
||||
|
||||
Free secure date, time;
|
||||
|
||||
Exception( fail_input ){
|
||||
Msg_yellow("Use:\n addhour <[-]nHours|[-]hh:mm[:ss]|[-]hh,mm>\n"
|
||||
"e.g.\n addhour 12 (add 12 hours)\n addhour 12:15 (add 12 hours + 15 mins)\n"
|
||||
" addhour -04:45 (subtract 4 hours + 45 mins)\n"
|
||||
" addhour 72 (add 72 hours)\n addhour -48,3 (subtract 48 hours + 3 mins)\n"
|
||||
" addhour 0,-15 (subtract 15 mins = -00:15)");
|
||||
}
|
||||
Exception( fail_time ){
|
||||
Msg_yellowf("Bad format time: %s (valid time: hh:mm[:ss])\n",cTime );
|
||||
Free secure cTime;
|
||||
}
|
||||
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue