mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 08:46:42 +08:00
128 lines
2.7 KiB
C
128 lines
2.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_date)
|
|
#include <varch/command.h>
|
|
#include <varch/date.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "date.h"
|
|
#endif
|
|
|
|
#if 0
|
|
static int century_days(int century)
|
|
{
|
|
int days = 0;
|
|
int year = (century - 1) * 100 + 1;
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
days += date_year_days(year + i);
|
|
}
|
|
|
|
return days;
|
|
}
|
|
|
|
static int thousand2_days(int base)
|
|
{
|
|
int days = 0;
|
|
|
|
for (int i = 0; i < 2000; i++)
|
|
{
|
|
days += date_year_days(base + i);
|
|
}
|
|
|
|
return days;
|
|
}
|
|
|
|
static int thousand3_days(int base)
|
|
{
|
|
int days = 0;
|
|
int century = (base / 100) + 1;
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
// days += century_days(century + i);
|
|
days += date_century_days(century + i);
|
|
}
|
|
|
|
return days;
|
|
}
|
|
#endif
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: date [opt] [arg]\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
"\n"
|
|
"argument:\n"
|
|
" <read> Test default read function\n"
|
|
" <write> Test default write function\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "hv");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
case 'v' :
|
|
printf("date version %d.%d.%d\r\n", DATE_V_MAJOR, DATE_V_MINOR, DATE_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
printf("month days %d\r\n", date_month_days(2024, 11));
|
|
printf("date_isleap %d\r\n", date_isleap(1582));
|
|
// printf("date_current_days %d\r\n", date_current_days(DATE(1,1,1)));
|
|
// printf("date_current_days %d\r\n", date_current_days(DATE(2000,12,31)));
|
|
// printf("date_current_days %d\r\n", date_current_days(DATE(2001,1,1)));
|
|
// printf("date_current_days %d\r\n", date_current_days(DATE(2024,11,9)));
|
|
printf("date_get_week %d\r\n", date_get_week(DATE(2024,11,11)));
|
|
|
|
printf("date_diff_days %d\r\n", date_diff_days(DATE(2018,3,14), DATE(2024,11,10)));
|
|
|
|
// DATE date = date_from_days(date_current_days(DATE(2024,11,30)));
|
|
DATE date = date_offset(DATE(2024,11,30), -1);
|
|
|
|
printf("%d.%d.%d\r\n", date.year,date.month,date.day);
|
|
|
|
date_show(1998,7);
|
|
date_show(2024,11);
|
|
date_show(2224,11);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if defined(TEST_TARGET_date)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_date(void)
|
|
{
|
|
command_export("date", test);
|
|
}
|
|
init_export_app(test_date);
|
|
#endif
|