Skip to content

Latest commit

 

History

History
174 lines (129 loc) · 7.23 KB

5.SexagenarySystem.md

File metadata and controls

174 lines (129 loc) · 7.23 KB

Working with Sexagenary cycle

The Sexagenary cycle is an inseparable system from the Lunar Calendar. lunar-calendar provides full functionality for interaction through the Sexagenary class.

The Sexagenary cycle include 10 Heavenly stems and 12 Earthly branches, combined together. Due to the lack of technical words to describe the proper names of the 10 Heavenly Stems in English, lunar-calendar uses the Vietnamese name instead, by removing the diacritics, e.g. For example Giáp will be identified as Giap, Thân will be identified as Than. You can completely customize them to use for specific purposes.

The following table lists the basic properties of the 10 Heavenly Stems and 12 Earthly Branches, which you need to grasp for convenient use:

Position Heavenly Stem's name Heavenly Stem's key Earthly branch's name Earthly branch's key
0 Giap giap Ty ty
1 At at Suu suu
2 Binh binh Dan dan
3 Dinh dinh Mao mao
4 Mau mau Thin thin
5 Ky ky Ti ti
6 Canh canh Ngo ngo
7 Tan tan Mui mui
8 Nham nham Than than
9 Quy quy Dau dau
10 Tuat tuat
11 Hoi hoi

Wildcard characters

The Sexagenary class provides a set of characters used to retrieve or format Heavenly Stem and Earthly Branch terms that represent an aspect of the Lunar milestone. The following table lists the supported list, where it can be seen that uppercase characters represent Heavenly Stems, and lowercase characters represent Earthly Branches.

Character Description
D Heavenly Stem of day
d Earthly Branch of day
M Heavenly Stem of month
m Earthly Branch of month
Y Heavenly Stem of year
y Earthly Branch of year
H Heavenly Stem of hour
h Earthly Branch of hour
N Heavenly Stem of first hour of day
W Heavenly Stem of day week leader
w Earthly Branch of week leader

Create sexagenary milestone

The Sexagenary class requires a Lunar milestone for calculation. Therefore, before creating an object, you need to determine the lunar time. The following example will print all the names of supported Sexagenary milestone corresponding to the Lunar date 2024-08-10 22:30:00 +07:00:

app.php

<?php

use LucNham\LunarCalendar\LunarDateTime;
use LucNham\LunarCalendar\Sexagenary;

require_once('./vendor/autoload.php');

$lunar = new LunarDateTime('2024-08-10 22:30 +0700');
$sexa = new Sexagenary($lunar);

print_r(
    [
        'Lunar date input' => $lunar->format('Y-m-d H:i:s P k'),
        'Day of__________' => "{$sexa->D->name} {$sexa->d->name}",
        'Month of________' => "{$sexa->M->name} {$sexa->m->name}",
        'Year of_________' => "{$sexa->Y->name} {$sexa->y->name}",
        'Hour of_________' => "{$sexa->H->name} {$sexa->h->name}",
        'Week of_________' => "{$sexa->W->name} {$sexa->w->name}",
    ]
);

Results:

Array
(
    [Lunar date input] => 2024-08-10 22:30:00 +07:00
    [Day of__________] => Ky Mao
    [Month of________] => Quy Dau
    [Year of_________] => Giap Thin
    [Hour of_________] => At Hoi
    [Week of_________] => Giap Tuat
)

Human-friendly format

The Sexagenary class supports friendly formatting of Sexagenary terms via the format() method. This method requires a format string as input parameter, with the following two characteristics:

  • If you only need to output the name of a single term, entering the corresponding wildcard with or without surrounded by square brackets [] works.
  • If multiple outputs need to be combined, wildcard characters must be enclosed within square brackets [].

app.php

<?php

use LucNham\LunarCalendar\LunarDateTime;
use LucNham\LunarCalendar\Sexagenary;

require_once('./vendor/autoload.php');

$lunar = new LunarDateTime('2024-08-10 22:30 +0700');
$sexa = new Sexagenary($lunar);

print_r(
    [
        'First method to get Terms of day________________' => $sexa->format('D'),
        'Second method to get Terms of day_______________' => $sexa->format('[D]'),
        'Fist method to get both Stem and Branch of day__' => $sexa->format('[D d]'),
        'Second method to get both Stem and Branch of day' => $sexa->format('[D+]'),
        'Mixed___________________________________________' => $sexa->format('Day of [D+], month of [M+], year of [Y+]')
    ]
);

Results:

Array
(
    [First method to get Terms of day________________] => Ky
    [Second method to get Terms of day_______________] => Ky
    [Fist method to get both Stem and Branch of day__] => Ky Mao
    [Second method to get both Stem and Branch of day] => Ky Mao
    [Mixed___________________________________________] => Day of Ky Mao, month of Quy Dau, year of Giap Thin
)

Sexagenary cycle localization

If you use Vietnamese, great, lunar-calendar already supports Vietnameseizing the Sexagenary terms. Usage is very simple, by passing additional parameters when initializing the Sexagenary object as follows:

app.php

<?php

use LucNham\LunarCalendar\LunarDateTime;
use LucNham\LunarCalendar\Sexagenary;
use LucNham\LunarCalendar\Terms\VnBranchIdentifier;
use LucNham\LunarCalendar\Terms\VnStemIdentifier;

require_once('./vendor/autoload.php');

$lunar = new LunarDateTime('2024-01-01 15:30 +0700');
$sexagenary = new Sexagenary(
    lunar: $lunar,
    stemIdetifier: VnStemIdentifier::class,
    branchIdentifier: VnBranchIdentifier::class,
);

$ouput = $sexagenary->format('Ngày [D+], tháng [M+], năm [Y+], giờ [H+]');

print_r($ouput);

Results:

Ngày Giáp Thìn, tháng Bính Dần, năm Giáp Thìn, giờ Nhâm Thân

The above example introduces one of many ways to localize Can Chi objects, you can completely handle this task with your own ideas.


Navigation menu

Introduction

System Requirements and Installation

Handling Lunar and Gregorian date

Working with Solar term