Skip to content

SexagenaryCycle

The SexagenaryCycle (干支) class.

Source code in src/ichingpy/model/sexagenary_cycle.py
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
class SexagenaryCycle:
    """The SexagenaryCycle (干支) class."""

    display_language = Language.CHINESE

    def __init__(self, stem: HeavenlyStem, branch: EarthlyBranch):
        """Initialize a new instance of the SexagenaryCycle class.

        Args:
            stem (HeavenlyStem): The HeavenlyStem to use in the SexagenaryCycle.
            branch (EarthlyBranch): The EarthlyBranch to use in the SexagenaryCycle.
        """
        if stem.value % 2 != branch.value % 2:
            raise ValueError("Invalid combination of HeavenlyStem and EarthlyBranch.")

        self.stem = stem
        self.branch = branch

    @property
    def value(self) -> int:
        """int: Represents the integer value of the SexagenaryCycle."""
        return (self.stem.value - 1) * 12 + self.branch.value

    @classmethod
    def from_int(cls, value: int) -> Self:
        """Create a new instance of the SexagenaryCycle from an integer.

        Args:
            value (int): The integer value
        """
        stem = HeavenlyStem((value - 1) % 10 + 1)
        branch = EarthlyBranch((value - 1) % 12 + 1)
        return cls(stem, branch)

    def __repr__(self) -> str:
        """Return a string representation of the SexagenaryCycle.

        Returns:
            str: A string representation of the SexagenaryCycle.
        """
        if self.display_language is Language.ENGLISH:
            return f"{self.stem.name}({self.stem.value}) {self.branch.name}({self.branch.value})"
        return f"{self.stem.label}{self.branch.label}"

    def __int__(self) -> int:
        """Convert the SexagenaryCycle to an integer.

        Returns:
            int: The integer value of the SexagenaryCycle.
        """
        return self.value

    def __add__(self, other: Self | int) -> "SexagenaryCycle":
        """Add an integer or a SexagenaryCycle to the SexagenaryCycle.

        Args:
            other (int): The integer to add to the SexagenaryCycle.

        Returns:
            SexagenaryCycle: The resulting SexagenaryCycle after addition.
        """
        if isinstance(other, int):
            return SexagenaryCycle(self.stem + other, self.branch + other)
        return SexagenaryCycle(self.stem + int(other.stem), self.branch + int(other.branch))

    def __radd__(self, other: Self | int) -> "SexagenaryCycle":
        return self.__add__(other)

    def __eq__(self, other: Any) -> bool:
        """Return True if the SexagenaryCycle is equal to the other SexagenaryCycle.

        Args:
            other (SexagenaryCycle): The other SexagenaryCycle to compare.

        Returns:
            bool: True if the SexagenaryCycle is equal to the other SexagenaryCycle.
        """
        return self.value == other.value

    def __sub__(self, other: Self | int) -> "SexagenaryCycle":
        """Subtract an integer or a SexagenaryCycle from the SexagenaryCycle.

        Args:
            other (int): The integer to subtract from the SexagenaryCycle.

        Returns:
            SexagenaryCycle: The resulting SexagenaryCycle after subtraction.
        """
        if isinstance(other, int):
            return SexagenaryCycle(self.stem - other, self.branch - other)
        return SexagenaryCycle(self.stem - int(other.stem), self.branch - int(other.branch))

    def __rsub__(self, other: Self | int) -> "SexagenaryCycle":
        return self.__sub__(other)

    @classmethod
    def set_language(cls, language: str) -> None:
        """Set the display language of the SexagenaryCycle.

        Args:
            language (Language): The display language to set.
        """
        cls.display_language = Language(language)

value property

int: Represents the integer value of the SexagenaryCycle.

__add__(other)

Add an integer or a SexagenaryCycle to the SexagenaryCycle.

Parameters:

Name Type Description Default
other int

The integer to add to the SexagenaryCycle.

required

Returns:

Name Type Description
SexagenaryCycle SexagenaryCycle

The resulting SexagenaryCycle after addition.

Source code in src/ichingpy/model/sexagenary_cycle.py
60
61
62
63
64
65
66
67
68
69
70
71
def __add__(self, other: Self | int) -> "SexagenaryCycle":
    """Add an integer or a SexagenaryCycle to the SexagenaryCycle.

    Args:
        other (int): The integer to add to the SexagenaryCycle.

    Returns:
        SexagenaryCycle: The resulting SexagenaryCycle after addition.
    """
    if isinstance(other, int):
        return SexagenaryCycle(self.stem + other, self.branch + other)
    return SexagenaryCycle(self.stem + int(other.stem), self.branch + int(other.branch))

__eq__(other)

Return True if the SexagenaryCycle is equal to the other SexagenaryCycle.

Parameters:

Name Type Description Default
other SexagenaryCycle

The other SexagenaryCycle to compare.

required

Returns:

Name Type Description
bool bool

True if the SexagenaryCycle is equal to the other SexagenaryCycle.

Source code in src/ichingpy/model/sexagenary_cycle.py
76
77
78
79
80
81
82
83
84
85
def __eq__(self, other: Any) -> bool:
    """Return True if the SexagenaryCycle is equal to the other SexagenaryCycle.

    Args:
        other (SexagenaryCycle): The other SexagenaryCycle to compare.

    Returns:
        bool: True if the SexagenaryCycle is equal to the other SexagenaryCycle.
    """
    return self.value == other.value

__init__(stem, branch)

Initialize a new instance of the SexagenaryCycle class.

Parameters:

Name Type Description Default
stem HeavenlyStem

The HeavenlyStem to use in the SexagenaryCycle.

required
branch EarthlyBranch

The EarthlyBranch to use in the SexagenaryCycle.

required
Source code in src/ichingpy/model/sexagenary_cycle.py
13
14
15
16
17
18
19
20
21
22
23
24
def __init__(self, stem: HeavenlyStem, branch: EarthlyBranch):
    """Initialize a new instance of the SexagenaryCycle class.

    Args:
        stem (HeavenlyStem): The HeavenlyStem to use in the SexagenaryCycle.
        branch (EarthlyBranch): The EarthlyBranch to use in the SexagenaryCycle.
    """
    if stem.value % 2 != branch.value % 2:
        raise ValueError("Invalid combination of HeavenlyStem and EarthlyBranch.")

    self.stem = stem
    self.branch = branch

__int__()

Convert the SexagenaryCycle to an integer.

Returns:

Name Type Description
int int

The integer value of the SexagenaryCycle.

Source code in src/ichingpy/model/sexagenary_cycle.py
52
53
54
55
56
57
58
def __int__(self) -> int:
    """Convert the SexagenaryCycle to an integer.

    Returns:
        int: The integer value of the SexagenaryCycle.
    """
    return self.value

__repr__()

Return a string representation of the SexagenaryCycle.

Returns:

Name Type Description
str str

A string representation of the SexagenaryCycle.

Source code in src/ichingpy/model/sexagenary_cycle.py
42
43
44
45
46
47
48
49
50
def __repr__(self) -> str:
    """Return a string representation of the SexagenaryCycle.

    Returns:
        str: A string representation of the SexagenaryCycle.
    """
    if self.display_language is Language.ENGLISH:
        return f"{self.stem.name}({self.stem.value}) {self.branch.name}({self.branch.value})"
    return f"{self.stem.label}{self.branch.label}"

__sub__(other)

Subtract an integer or a SexagenaryCycle from the SexagenaryCycle.

Parameters:

Name Type Description Default
other int

The integer to subtract from the SexagenaryCycle.

required

Returns:

Name Type Description
SexagenaryCycle SexagenaryCycle

The resulting SexagenaryCycle after subtraction.

Source code in src/ichingpy/model/sexagenary_cycle.py
87
88
89
90
91
92
93
94
95
96
97
98
def __sub__(self, other: Self | int) -> "SexagenaryCycle":
    """Subtract an integer or a SexagenaryCycle from the SexagenaryCycle.

    Args:
        other (int): The integer to subtract from the SexagenaryCycle.

    Returns:
        SexagenaryCycle: The resulting SexagenaryCycle after subtraction.
    """
    if isinstance(other, int):
        return SexagenaryCycle(self.stem - other, self.branch - other)
    return SexagenaryCycle(self.stem - int(other.stem), self.branch - int(other.branch))

from_int(value) classmethod

Create a new instance of the SexagenaryCycle from an integer.

Parameters:

Name Type Description Default
value int

The integer value

required
Source code in src/ichingpy/model/sexagenary_cycle.py
31
32
33
34
35
36
37
38
39
40
@classmethod
def from_int(cls, value: int) -> Self:
    """Create a new instance of the SexagenaryCycle from an integer.

    Args:
        value (int): The integer value
    """
    stem = HeavenlyStem((value - 1) % 10 + 1)
    branch = EarthlyBranch((value - 1) % 12 + 1)
    return cls(stem, branch)

set_language(language) classmethod

Set the display language of the SexagenaryCycle.

Parameters:

Name Type Description Default
language Language

The display language to set.

required
Source code in src/ichingpy/model/sexagenary_cycle.py
103
104
105
106
107
108
109
110
@classmethod
def set_language(cls, language: str) -> None:
    """Set the display language of the SexagenaryCycle.

    Args:
        language (Language): The display language to set.
    """
    cls.display_language = Language(language)