ref: 0853197432f336576c487b57d3708516b3d6b0b0
parent: 2ee5654130eb7579fc539f0021a6250baee10800
author: Jacobo Da Riva Muñoz <[email protected]>
date: Sun May 5 05:35:10 EDT 2024
"Refactor"
--- a/ddate.c
+++ b/ddate.c
@@ -29,9 +29,7 @@
#define leap_year( x ) ((x)%400 == 0 || (((x) % 4) == 0 && (x) % 100))
-int day_of_year(int d, int m, int y);
int curyday(void);
-int curmo(void);
int curyr(void);
static void
@@ -44,22 +42,18 @@
void
main(int argc, char *argv[])
{
- int y, m, d, dy, dd, leap_day;
+ int d, m, y, dd, dy, leap_day;
char *dw;
char *ds;
- leap_day = 0;
-
- if( argc == 1 ){
- /* Get the year, day and month of today*/
+ if( argc == 1){
+ /* Get the year and day*/
d = curyday();
- //m = curmo();
y = curyr();
- } else if( argc == 4 ) {
+ } else if( argc == 4 ){
d = atoi( argv[1] );
m = atoi( argv[2] );
y = atoi( argv[3] );
- d = day_of_year(d, m, y);
} else {
usage();
}
@@ -84,22 +78,8 @@
} else {
print("%s, %d of %s, YOLD %d\n", day_of_week(d%5), dd, ds, dy);
}
-
}
-int
-day_of_year( int d, int m, int y)
-{
- int ml[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- for( ; m > 1; m --){
- d = d + ml[ m - 2 ];
- if( m == 3 && leap_year(y)){
- d = d + 1;
- }
- }
- return d;
-}
-
/*
* system dependent
* get current day of the year, month and year
@@ -111,15 +91,6 @@
tm = localtime(time(0));
return tm->yday+1;
-}
-
-int
-curmo(void)
-{
- Tm *tm;
-
- tm = localtime(time(0));
- return tm->mon+1;
}
int