相对于复活节及时计算事件

Calculating events in time, with respect to easter

假设约翰的周年纪念日恰好在复活节。约翰尼的周年纪念日总是在复活节后的一周。艾伦的周年纪念日是五旬节前一周(复活节后 42 天)。

如何使用 shell 脚本计算他们的生日日期(数字和日期名称)和月份。对于所有未来年份。

我知道,我可以用 ncal -e "year" 计算复活节的日子。 我在 C 中所做的是:

typedef struct {
  int day;
  int month;
  int year;
} Date;

然后我计算复活节那天(用高斯算法)。 return 五旬节函数的日、月、年,它采用日+49 并减少日,增加月。

因此:

  1. 在 shell 中,如何转换 ncal -e 从“January 1 2019" 到 "1 1 2019" 只有 shell。
  2. 如果我有这个怎么办 你会开始为上面的故事制定规则吗? (为了 生日)
Date easter(int Y)
{
    Date date;
    int C = floor(Y/100);
    int N = Y - 19*floor(Y/19);
    int K = floor((C - 17)/25);
    int I = C - floor(C/4) - floor((C - K)/3) + 19*N + 15;
    I = I - 30*floor((I/30));
    I = I - floor(I/28)*(1 - floor(I/28)*floor(29/(I + 1))*floor((21 - N)/11));
    int J = Y + floor(Y/4) + I + 2 - C + floor(C/4);
    J = J - 7*floor(J/7);
    int L = I - J;
    int M = 3 + floor((L + 40)/44);
    int D = L + 28 - 31*floor(M/4);

    date.d = D;
    date.m = M;
    date.y = Y;
    return date;
}

只需编写一个调用 ncal -e

的函数
easter() {
    local year=${1:-$(date "+%Y")}   # use this year if no arg provided
    local easter=$(ncal -e "$year")  # month day year
    date -d "$easter" "+%F"          # YYYY-mm-dd
}

然后

$ easter
2019-04-21
$ easter 2018
2018-04-01
$ easter 2020
2020-04-12
$ date -d "$(easter) - 1 week" "+%F"
2019-04-14
$ date -d "$(easter) + 1 week" "+%F"
2019-04-28

如果您选择,请使用不同的日期格式。