mirror of
https://github.com/infinet/lunar-calendar.git
synced 2026-01-12 21:17:00 +08:00
21
README.md
21
README.md
@@ -51,7 +51,7 @@ calendar, thunderbird + lightning插件, iphone/ipad, 安卓都支持。
|
||||
|
||||
### C 版本
|
||||
|
||||
C版本速度更快,但暂时只在终端上输出农历,不能直接生成ical文件。
|
||||
C版本速度更快,但暂时只在终端上输出ical。用户必须使用`>`将stdout的结果导入到指定文件以生成ical文件。
|
||||
|
||||
编译:
|
||||
|
||||
@@ -60,12 +60,11 @@ C版本速度更快,但暂时只在终端上输出农历,不能直接生成i
|
||||
|
||||
运行:
|
||||
|
||||
生成某年农历
|
||||
$ ./lunarcal 2015
|
||||
|
||||
生成数年农历
|
||||
$ ./lunarcal 2015 2019
|
||||
#生成某年农历
|
||||
$ ./lunarcal 2016 > chinese_lunar_2016.ics
|
||||
|
||||
#生成数年农历
|
||||
$ ./lunarcal 2016 2019 > chinese_lunar_2016_2019.ics
|
||||
|
||||
### 版权
|
||||
|
||||
@@ -148,11 +147,13 @@ The date must in ISO format.
|
||||
|
||||
There is also a C version under directory "c". Run `make` to generate the
|
||||
executable `lunarcal`. Run `lunarcal` with year will print out the Chinese Lunar
|
||||
Calendar to terminal, for example:
|
||||
Calendar in ical format to the terminal. Use `>` to redirect the output to a file, for example:
|
||||
|
||||
$ ./lunarcal 2015
|
||||
or
|
||||
$ ./lunarcal 2015 2019
|
||||
# Specific year
|
||||
$ ./lunarcal 2016 > chinese_lunar_2016.ics
|
||||
|
||||
# or multiple years
|
||||
$ ./lunarcal 2016 2019 > chinese_lunar_2016_2019.ics
|
||||
|
||||
|
||||
[Contact me](mailto: weichen302@gmail.com)
|
||||
|
||||
@@ -196,7 +196,9 @@ size_t jdftime(char *isodt, double jd, char *fmt, double tz, int isut)
|
||||
M = ms / 60;
|
||||
S = ms % 60;
|
||||
|
||||
if (strcmp(fmt, "%y-%m-%d") == 0) {
|
||||
if (strcmp(fmt, "%y%m%d") == 0) {
|
||||
sprintf(isodt, "%04d%02d%02d", y, m, d);
|
||||
} else if (strcmp(fmt, "%y-%m-%d") == 0) {
|
||||
sprintf(isodt, "%04d-%02d-%02d", y, m, d);
|
||||
} else if (strcmp(fmt, "%y-%m-%d %H:%M") == 0) {
|
||||
sprintf(isodt, "%04d-%02d-%02d %02d:%02d", y, m, d, H, M);
|
||||
|
||||
@@ -17,10 +17,19 @@ int main(int argc, char *argv[])
|
||||
exit(2);
|
||||
}
|
||||
|
||||
printf("BEGIN:VCALENDAR\n"
|
||||
"PRODID:-//Chen Wei//Chinese Lunar Calendar//EN\n"
|
||||
"VERSION:2.0\n"
|
||||
"CALSCALE:GREGORIAN\n"
|
||||
"METHOD:PUBLISH\n"
|
||||
"X-WR-CALNAME:农历\n"
|
||||
"X-WR-TIMEZONE:Asia/Shanghai\n"
|
||||
"X-WR-CALDESC:中国农历%d-%d, 包括节气. 数据来自香港天文台\n", start, end);
|
||||
while (start <= end) {
|
||||
cn_lunarcal(start);
|
||||
start++;
|
||||
}
|
||||
printf("END:VCALENDAR\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "astro.h"
|
||||
#include "lunarcalbase.h"
|
||||
|
||||
@@ -180,6 +181,7 @@ int mark_month_day(struct lunarcal *lcs[])
|
||||
lc_start = newmoons[firstnm_offset];
|
||||
lc_end = solarterms[MAX_SOLARTERMS -1];
|
||||
jd = lc_start;
|
||||
month_day1 = 0;
|
||||
len = 0;
|
||||
while (jd < lc_end) { /* fill in days into array lcs */
|
||||
/* scan for month jd belongs */
|
||||
@@ -280,14 +282,30 @@ void print_lunarcal(struct lunarcal *p[], int len)
|
||||
int i;
|
||||
char isodate[30];
|
||||
char tmp[30];
|
||||
char dtstart[30];
|
||||
char dtend[30];
|
||||
char utcstamp[30];
|
||||
struct tm* utc_time;
|
||||
time_t t = time(NULL);
|
||||
utc_time = gmtime(&t);
|
||||
sprintf (utcstamp, "%04d%02d%02dT%02d%02d%02dZ", 1900+utc_time->tm_year, utc_time->tm_mon, utc_time->tm_mday, utc_time->tm_hour, utc_time->tm_min, utc_time->tm_sec);
|
||||
for (i = 0; i < len; i++) {
|
||||
jdftime(isodate, p[i]->jd, "%y-%m-%d", 0, 0);
|
||||
jdftime(dtstart, p[i]->jd, "%y%m%d", 0, 0);
|
||||
jdftime(dtend, p[i]->jd, "%y%m%d", 24, 0);
|
||||
if (p[i]->day == 1)
|
||||
sprintf(tmp, "%s", CN_MON[p[i]->month]);
|
||||
else
|
||||
sprintf(tmp, "%s", CN_DAY[p[i]->day]);
|
||||
if (p[i]->solarterm > -1)
|
||||
sprintf(tmp, "%s %s", tmp, CN_SOLARTERM[p[i]->solarterm]);
|
||||
printf("%s %s \n", isodate, tmp);
|
||||
printf("BEGIN:VEVENT\n"
|
||||
"DTSTAMP:%s\n"
|
||||
"UID:%s-lc@infinet.github.io\n"
|
||||
"DTSTART;VALUE=DATE:%s\n"
|
||||
"DTEND;VALUE=DATE:%s\n"
|
||||
"STATUS:CONFIRMED\n"
|
||||
"SUMMARY:%s\n"
|
||||
"END:VEVENT\n", utcstamp, isodate, dtstart, dtend, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user