Linux shell converts calendars to Lunar Calendar

Source: Internet
Author: User

I have nothing to worry about. I want to use shell in Linux to write a script for converting the Gregorian calendar to the lunar calendar. It will take about a week to complete. Now let's share it with you.

The principle of this script is the look-up table method (because there is an error in the formula). Based on the lunar new year as the benchmark, two different Chinese calendars before and after the Lunar New Year are calculated.

Before writing this script, you want to add the Gregorian calendar and lunar date to the Linux terminal command prompt. There is Lunar software in Ubuntu to get the Lunar date, but there is no similar software in Fedora or CentOS, so I want to implement one by myself, but I write it in other languages on the Internet, it is unnecessary to write more data. So I want to use shell to write one.

Function: Converts a calendar date to a calendar date.

Time Range: 1901 ~ 2099, the time corresponding to the calendar year is 4598 ~ 4796

Parameter format(If NO parameter is set, the default value is the current system date.): yyyymmdd

For example, February 1, January 1, 2013:

Complete data:

Http://files.cnblogs.com/snowsolf/lunar_20130711.zip

Files in the package:

Lunar. sh main script, specific implementation

Datebases lunar metadata

Change. log change log

Readme script instructions and precautions

The main script lunar. sh code is as follows:

#!/bin/= =  ] && DATE=$( +%Y%m%=$( $DATE | =$( $DATE | =$( $DATE | =$( -d $DATE +%=$( /$date_year/!d databases | =$( /$date_year/!d databases | =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |bc | -e :a -e =$( -d $date_year$new_year_month$new_year_day +%=$( $date_days - $new_year_days + =  [  -le  ]; ==$(($date_year-=$( /$date_year/!d databases | =$( /$date_year/!d databases | =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |=$( $lunar_year_data_bin | -e  =  ] && lunar_month_all_bin=$( $lunar_year_data_bin | -e =$( $lunar_month_all_bin | -e  | -e  [  =  ];== i        [  -gt  ]; =$(($lunar_day -=$(($lunar_month +    ==$((-=$( $lunar_month_all_bin |=$( $lunar_month_all_bin | -e  | -e  i        [  -gt  ]; =$(($lunar_day -=$(($lunar_month - =$(($i -     [  =  ];      $lunar_year-$lunar_month-    [  -ge  ];        $lunar_year-$lunar_month- [  =  ];        [  =  ];=$(($lunar_month -  $lunar_year-*$lunar_month-=$(($lunar_month -  $lunar_year-$lunar_month-          $lunar_year-$lunar_month-
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.