Skip to content

Commit

Permalink
add ganzhi for luck pillars (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommitoan authored Jul 31, 2024
1 parent 8c4577d commit 1997766
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ import (
func main() {
// Calculate current ba-zi chart
loc, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
now := time.Now()
now := time.Now()
gender := 0 // 0 = female & 1 = male

/* Example:
Time to calculate: 1990-12-31 6:30 - Timezone: HoChiMinh / Vietnam
Time to calculate: 1990-12-31 6:30 - Timezone: HoChiMinh / Vietnam - Gender: Male
loc, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
now := time.Date(1990, time.Month(12), 31, 6, 30, 0, 0, location)
now := time.Date(1990, time.Month(12), 31, 6, 30, 0, 0, loc)
gender := 1
*/

chart, err := bazica.GetBaziChart(now, loc)
chart, err := bazica.GetBaziChart(now, loc, gender)
if err != nil {
fmt.Println(err)
}
Expand Down
14 changes: 14 additions & 0 deletions internal/luckpillars/get_luck_pillars.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/tommitoan/bazica/internal/ultis"
"github.com/tommitoan/bazica/model"
"log/slog"
"strings"
"time"
)

Expand Down Expand Up @@ -38,6 +39,7 @@ func GetLuckPillars(fourPillars *model.FourPillars, gender, passed, remaining in
// Calculate the remaining 11 luck pillars (excluding age and year)
var branchValue int = fourPillars.MonthPillar.EarthlyBranch.Value
var stemValue int = fourPillars.MonthPillar.HeavenlyStem.Value

// pillar1
for i := 1; i < 12; i++ {
var luckPeriod time.Time
Expand Down Expand Up @@ -81,6 +83,18 @@ func GetLuckPillars(fourPillars *model.FourPillars, gender, passed, remaining in
YearEnd: luckPeriod.Year() + 9,
}

var ganzhi, mainElement string
var valueElement int
var tempStemBranch strings.Builder
tempStemBranch.WriteString(tempLuckPillars.HeavenlyStem.Name)
tempStemBranch.WriteString(" ")
tempStemBranch.WriteString(tempLuckPillars.EarthlyBranch.Name)

ganzhi, mainElement, valueElement = ultis.GetGanzhi(tempStemBranch.String())
tempLuckPillars.GanZhi.Name = ganzhi
tempLuckPillars.GanZhi.ElementName = mainElement
tempLuckPillars.GanZhi.ElementValue = valueElement

luckPillars.LuckPillars = append(luckPillars.LuckPillars, tempLuckPillars)
}

Expand Down
1 change: 1 addition & 0 deletions model/model_bazi-chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LuckPillar struct {
Number int `json:"number"`
HeavenlyStem HeavenlyStem `json:"heavenly_stem"`
EarthlyBranch EarthlyBranch `json:"earthly_branch"`
GanZhi GanZhi `json:"gan_zhi"`
YearStart int `json:"year_start"`
YearEnd int `json:"year_end"`
Time time.Time `json:"time"`
Expand Down

0 comments on commit 1997766

Please sign in to comment.