Giter Site home page Giter Site logo

bazica's Introduction

GitHub release Go Reference Go Report Card License

Bazica (Ba-zi Chart Calculator)

Convert Solar Calendar to Bazi Chart (Chinese astrology) with the year, month, day and hour of birth information (in Go)


Getting started with bazica

Prerequisites

  • Go: any one of the three latest major releases (we test it with these).

Importing Bazica

With Go module support, simply add the following import

import "github.com/tommitoan/bazica"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the bazica package:

go get -u github.com/tommitoan/bazica@latest

go mod vendor # For fetching full model

Get Data (Important) ⚠️⚠️

This module provides data related to solar terms, zodiac signs, and the 60-year era cycle.

For your convenience, the data is also summarized in JSON files and located in the data folder.

To use this module:

Clone or copy this repository to your project directory. Access the JSON files located in the data folder. Please note: You'll need to manually copy the relevant JSON files from the data folder into your project to utilize the data within your application.

Example:

Before Install              
├── your_project_folder
│   ├── app
│   ├── main.go
│   ├── go.mod

After Install and Clone `data` folder
├── your_project_folder
│   ├── app
│   ├── data
│   │   ├── solar-term.json
│   │   ├── zodiac-signs.json
│   │   ├── ...(updated)...
│   ├── main.go
│   ├── go.mod

How to use

package main

import (
	"encoding/json"
	"fmt"
	"github.com/tommitoan/bazica"
	"time"
)

func main() {
	// Calculate current ba-zi chart
	loc, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
	now := time.Now() 
	
	/* Example: 
	Time to calculate: 1990-12-31 6:30 - Timezone: HoChiMinh / Vietnam
	loc, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
	now := time.Date(1990, time.Month(12), 31, 6, 30, 0, 0, location)
	*/

	chart, err := bazica.GetBaziChart(now, loc)
	if err != nil {
		fmt.Println(err)
	}
	jsonData, _ := json.Marshal(chart)
	fmt.Println(string(jsonData))
}

Note

Data Input Limitations:

Due to the specific calculations and algorithms used in this package, it is currently designed to handle date inputs ranging from January 1, 1900, to December 31, 2100.
Dates before 1900 or after 2100 may fall outside the scope of supported calendar systems or lead to inaccurate results.

If you require calculations for dates outside this range, please consider alternative libraries or solutions.

Ho Chi Minh City 1975

Ho Chi Minh City (formerly Saigon) has gone through time zone changes throughout history. Notably:
Before 1975: South Vietnam (including Saigon) used UTC+8.
After 1975: The unified Vietnam adopted UTC+7.


References

This project drew inspiration and information from the following sources:

  • Thời Gian - A comprehensive resource for understanding the Vietnamese calendar system.
  • Chinese Fortune Calendar - Provided insights into the Chinese calendar, calculations, and cultural significance.

Document

https://www.geomancy.net/forums/topic/10229-understand-the-chinese-lunar-and-xia-calendar-in-ba-zi-four-pillars-used-by-various-masters-and-why-not-to-totally-depend-on-just-the-xia-hsia-seasonal-solar-calendar-alone/

For a given date and time of birth, the Hsia Calendar is used to obtain the Heavenly Stems and Earthly Branches with which to construct the Four Pillars of Destiny (四柱) of a person. The Four Pillars of Destiny are also known as the Ba Zi (八字), literally the Eight Characters of a person's birth. In ancient China, one use of this form of divination was to select a suitable marriage partner.

The Four Pillars of Destiny are the Year Pillar, the Month Pillar, the Day Pillar and the Hour Pillar. Each Pillar is made up of two components, namely the Heavenly Stem and the Earthly Branch, both of which are read from the Hsia Calendar.

The Hsia Calendar is also used in various types of Feng Shui, or Chinese Geomancy, such as the Flying Star Feng Shui.

A ba zi chart done with mixed Lunar & Seasonal (Solar Term) Calendar will look like this:-

Date time: 2024-07-05 22:00 UTC+7 (Vietnam)  

Year: Yang Wood - Dragon (Lunar Calendar Year)  
Month: Yang Metal - Horse (Solar-Term Calendar Month)  
Day: Yang Metal - Horse (Lunar Calendar Day)   
Hour: Yin Wood - Pig (Zodiac Hour)

bazica's People

Contributors

tommitoan avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.