lunar-java

repository·master·Indexed 21 days ago

https://github.com/6tail/lunar-java

A zero-dependency Java library for managing Gregorian, Lunar, Taoist, and Buddhist calendars. It supports Java 1.5 and above, providing extensive data for the traditional Chinese almanac, including zodiacs, solar terms, stem-branch (GanZhi) cycles, five elements, and auspicious/inauspicious directions.

Tokens
1.2K
Snippets
5
Records
6
Agent score
26%

What's inside lunar-java

  1. Overview of lunar-java capabilities

    master

    The lunar-java library is a zero-dependency tool for handling multiple calendar systems including:

    • Solar (Gregorian) Calendar
    • Lunar Calendar (including traditional almanac/Huangli data)
    • Taoist and Buddhist Calendars

    Key features include:

    • Zodiac signs and Stem-Branch (GanZhi) cycles
    • Solar terms (JieQi) and festivals
    • Traditional almanac data: Pengzu Baiji, auspicious directions (Gods/Fortune/Wealth), clashes (Chong), and Sha directions
    • Five Elements (WuXing), Ten Gods (ShiShen), and Star Constellations
    • Legal holidays and adjusted working days

    Note on GanZhi calculation:

    • Years: Supports calculation based on the first day of the first lunar month, the day of the Start of Spring (Lichun), or the exact moment of the Start of Spring transition.
    • Months: Supports calculation based on the day of a solar term or the exact moment of the solar term transition.
  2. Download lunar-java JAR

    master

    If you are not using a build tool like Maven, you can download the latest JAR file directly from the GitHub releases page to ensure you have the most recent bug fixes.

    https://github.com/6tail/lunar-java/releases
  3. Install lunar via Maven

    master

    To use the lunar library in your Java project, add the following dependency to your pom.xml file. This library supports Java 1.5 and above.

    <dependency>
      <groupId>cn.6tail</groupId>
      <artifactId>lunar</artifactId>
      <version>1.7.7</version>
    </dependency>
  4. Install lunar-java via Maven

    master

    To use lunar-java in your Java project, add the following dependency to your pom.xml file. This library has no third-party dependencies and supports Java 1.5 and above.

    <dependency>
      <groupId>cn.6tail</groupId>
      <artifactId>lunar</artifactId>
      <version>1.7.7</version>
    </dependency>
  5. Use the Lunar class for Chinese Calendar data

    master

    The Lunar class is the primary entry point for accessing Chinese calendar information (Lunar, Taoist, Buddhist, etc.). You can instantiate it using the current date or by specifying a specific year, month, and day. It provides access to solar dates, zodiac signs, stem-branch (GanZhi) information, solar terms, and various traditional almanac details (e.g., auspicious directions, clashes, and five elements).

    import com.nlf.calendar.Lunar;
    
    /**
     * Lunar date example
     */
    public class LunarSample{
      public static void main(String[] args){
        // Specify a specific lunar date (Year, Month, Day)
        Lunar date = new Lunar(1986, 4, 21);
        
        // Print full lunar description
        System.out.println(date.toFullString());
        
        // Print corresponding solar date description
        System.out.println(date.getSolar().toFullString());
      }
    }
  6. Use the Lunar class for Chinese Lunar dates

    master

    The com.nlf.calendar.Lunar class is the primary entry point for working with the Chinese Lunar calendar. You can instantiate it using the current date (no arguments) or by specifying a specific year, month, and day.

    Key methods:

    • toFullString(): Returns a highly detailed string representation of the lunar date, including the sexagenary cycle (stems/branches), zodiac, solar terms, and various traditional Chinese astrological information.
    • getSolar(): Returns a Solar object representing the corresponding Gregorian date.
    import com.nlf.calendar.Lunar;
    
    public class LunarSample{
      public static void main(String[] args){
        // Specify a specific lunar date (Year, Month, Day)
        Lunar date = new Lunar(1986, 4, 21);
        
        // Print detailed lunar information
        System.out.println(date.toFullString());
        
        // Print corresponding solar (Gregorian) information
        System.out.println(date.getSolar().toFullString());
      }
    }