From 3d37ed45efc61becda9f00fa63f702737f42b039 Mon Sep 17 00:00:00 2001 From: Putu Aditya Date: Mon, 28 Aug 2023 02:26:51 +0800 Subject: [PATCH] v1.0.0 --- .github/workflows/security.yml | 16 ++ .github/workflows/unit_test.yml | 43 ++++ .gitignore | 21 ++ LICENSE | 21 ++ README.md | 63 ++++++ asta_wara.go | 42 ++++ catur_wara.go | 25 +++ dasa_wara.go | 48 +++++ dwi_wara.go | 24 +++ eka_jalarsi.go | 102 ++++++++++ eka_wara.go | 21 ++ go.mod | 14 ++ go.sum | 77 +++++++ ingkel.go | 29 +++ jejapan.go | 29 +++ lintang.go | 123 +++++++++++ panca_wara.go | 34 ++++ pansa_suda.go | 31 +++ pararasan.go | 48 +++++ pivot.go | 34 ++++ pratithi_samut_pada.go | 54 +++++ rahinan.go | 223 ++++++++++++++++++++ rakam.go | 36 ++++ range.go | 85 ++++++++ range_test.go | 103 ++++++++++ sad_wara.go | 29 +++ saka.go | 167 +++++++++++++++ saka_test.go | 165 +++++++++++++++ sanga_wara.go | 45 ++++ sapta_wara.go | 39 ++++ sasih.go | 134 ++++++++++++ struct.go | 15 ++ twi_wara.go | 23 +++ utils.go | 349 ++++++++++++++++++++++++++++++++ watek_alit.go | 25 +++ watek_madya.go | 27 +++ wuku.go | 114 +++++++++++ 37 files changed, 2478 insertions(+) create mode 100644 .github/workflows/security.yml create mode 100644 .github/workflows/unit_test.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 asta_wara.go create mode 100644 catur_wara.go create mode 100644 dasa_wara.go create mode 100644 dwi_wara.go create mode 100644 eka_jalarsi.go create mode 100644 eka_wara.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 ingkel.go create mode 100644 jejapan.go create mode 100644 lintang.go create mode 100644 panca_wara.go create mode 100644 pansa_suda.go create mode 100644 pararasan.go create mode 100644 pivot.go create mode 100644 pratithi_samut_pada.go create mode 100644 rahinan.go create mode 100644 rakam.go create mode 100644 range.go create mode 100644 range_test.go create mode 100644 sad_wara.go create mode 100644 saka.go create mode 100644 saka_test.go create mode 100644 sanga_wara.go create mode 100644 sapta_wara.go create mode 100644 sasih.go create mode 100644 struct.go create mode 100644 twi_wara.go create mode 100644 utils.go create mode 100644 watek_alit.go create mode 100644 watek_madya.go create mode 100644 wuku.go diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..c739b77 --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,16 @@ +on: + pull_request: + paths: + - '**.go' + push: + branches: + - main +name: Security +jobs: + GoSecurity: + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v3 + - name: Run Gosec + uses: securego/gosec@master \ No newline at end of file diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml new file mode 100644 index 0000000..3b8fa17 --- /dev/null +++ b/.github/workflows/unit_test.yml @@ -0,0 +1,43 @@ +name: Unit Testing + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + utils-test: + strategy: + matrix: + go-version: [1.19.x,1.20.x,1.21.x] + platform: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Setup Golang caches + uses: actions/cache@v3 + with: + # In order: + # * Module download cache + # * Build cache (Linux) + # * Build cache (Mac) + # * Build cache (Windows) + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/Library/Caches/go-build + ~\AppData\Local\go-build + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}- + - name: Test + run: go test -v ./... \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7cd1091 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e1bb69 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Portalnesia + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..77b7438 --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +[![Go Reference](https://pkg.go.dev/badge/go.portalnesia.com/saka.svg)](https://pkg.go.dev/go.portalnesia.com/saka) ![Go](https://github.com/portalnesia/go-saka/actions/workflows/unit_test.yml/badge.svg) + +# Saka + +Saka is a Go library for working with the Balinese calendar system. This library provides functionalities to convert Gregorian dates to Balinese calendar dates and vice versa. It also offers features to retrieve Hindu holidays, important cultural events, and auspicious days. + +## Installation + +To use Saka in your Go project, you need to install it using go get: + +```bash +go get -u go.portalnesia.com/saka +``` + +## Usage + +```go +package main + +import ( + "go.portalnesia.com/saka" + "github.com/golang-module/carbon" +) + +func oneDate() { + saka_instance := saka.New() + + // Get information about the date + saka_instance.EkaWara + saka_instance.PancaWara + saka_instance.Sasih + // and others... + + all_rahinan := saka_instance.Rahinan() + // todo with list rahinan + if all_rahinan[0] == saka.Enum.Rahinan.Nyepi { + + } + // and others... + +} + +func rangeDate() { + d1 := carbon.CreateFromDate(2023, 8, 27) + d2 := carbon.CreateFromDate(2023, 8, 31) + + saka_instance := saka.NewRange(d1,d2) + + // List all rahinan + all_rahinan := saka_instance.ListAllRahinan() + + // List by date + date_list := saka_instance.ListByDate() +} +``` + +## Go Reference + +[pkg.go.dev/go.portalnesia.com/saka](https://pkg.go.dev/go.portalnesia.com/saka) + +## Thanks To + +- [github.com/peradnya/balinese-date-js-lib](https://github.com/peradnya/balinese-date-js-lib) - Balinese calendar library for Javascript/Typescript \ No newline at end of file diff --git a/asta_wara.go b/asta_wara.go new file mode 100644 index 0000000..8d1ab82 --- /dev/null +++ b/asta_wara.go @@ -0,0 +1,42 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type AstaWara struct { + Sri Wara + Indra Wara + Guru Wara + Yama Wara + Ludra Wara + Brahma Wara + Kala Wara + Uma Wara +} + +func newAstaWara() AstaWara { + return AstaWara{ + Sri: Wara{ID: 0, Urip: 6, Name: "Sri"}, + Indra: Wara{ID: 1, Urip: 5, Name: "Indra"}, + Guru: Wara{ID: 2, Urip: 8, Name: "Guru"}, + Yama: Wara{ID: 3, Urip: 9, Name: "Yama"}, + Ludra: Wara{ID: 4, Urip: 3, Name: "Ludra"}, + Brahma: Wara{ID: 5, Urip: 7, Name: "Brahma"}, + Kala: Wara{ID: 6, Urip: 1, Name: "Kala"}, + Uma: Wara{ID: 7, Urip: 4, Name: "Uma"}, + } +} + +func newAstaWaraSlice() []Wara { + astawara := newAstaWara() + return []Wara{ + astawara.Sri, + astawara.Indra, + astawara.Guru, + astawara.Yama, + astawara.Ludra, + astawara.Brahma, + astawara.Kala, + astawara.Uma, + } +} diff --git a/catur_wara.go b/catur_wara.go new file mode 100644 index 0000000..0b6a340 --- /dev/null +++ b/catur_wara.go @@ -0,0 +1,25 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type CaturWara struct { + Sri Wara + Laba Wara + Jaya Wara + Menala Wara +} + +func newCaturWara() CaturWara { + return CaturWara{ + Sri: Wara{0, 6, "Sri"}, + Laba: Wara{1, 5, "Laba"}, + Jaya: Wara{2, 1, "Jaya"}, + Menala: Wara{3, 8, "Menala"}, + } +} + +func newCaturWaraSlice() []Wara { + wara := newCaturWara() + return []Wara{wara.Sri, wara.Laba, wara.Jaya, wara.Menala} +} diff --git a/dasa_wara.go b/dasa_wara.go new file mode 100644 index 0000000..0a7a136 --- /dev/null +++ b/dasa_wara.go @@ -0,0 +1,48 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type DasaWara struct { + Pandita Wara + Pati Wara + Suka Wara + Duka Wara + Sri Wara + Manuh Wara + Manusa Wara + Raja Wara + Dewa Wara + Raksasa Wara +} + +func newDasaWara() DasaWara { + return DasaWara{ + Pandita: Wara{0, 5, "Pandita"}, + Pati: Wara{1, 7, "Pati"}, + Suka: Wara{2, 10, "Suka"}, + Duka: Wara{3, 4, "Duka"}, + Sri: Wara{4, 6, "Sri"}, + Manuh: Wara{5, 2, "Manuh"}, + Manusa: Wara{6, 3, "Manusa"}, + Raja: Wara{7, 8, "Raja"}, + Dewa: Wara{8, 9, "Dewa"}, + Raksasa: Wara{9, 1, "Raksasa"}, + } +} + +func newDasaWaraSlice() []Wara { + wara := newDasaWara() + return []Wara{ + wara.Pandita, + wara.Pati, + wara.Suka, + wara.Duka, + wara.Sri, + wara.Manuh, + wara.Manusa, + wara.Raja, + wara.Dewa, + wara.Raksasa, + } +} diff --git a/dwi_wara.go b/dwi_wara.go new file mode 100644 index 0000000..fafbddb --- /dev/null +++ b/dwi_wara.go @@ -0,0 +1,24 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type DwiWara struct { + Menga Wara + Pepet Wara +} + +func newDwiWara() DwiWara { + return DwiWara{ + Menga: Wara{0, 5, "Menga"}, + Pepet: Wara{1, 4, "Pepet"}, + } +} + +func newDwiWaraSlice() []Wara { + wara := newDwiWara() + return []Wara{ + wara.Menga, + wara.Pepet, + } +} diff --git a/eka_jalarsi.go b/eka_jalarsi.go new file mode 100644 index 0000000..f73442a --- /dev/null +++ b/eka_jalarsi.go @@ -0,0 +1,102 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type EkaJalaRsi struct { + BagnaMapasah Data + BahuPutra Data + BahuAstawa Data + BuatKingking Data + BuatLara Data + BuatMerang Data + BuatSebet Data + BuatSuka Data + DahatKingking Data + Kameranan Data + Kamertaan Data + Kasobagian Data + KinasihanAmerta Data + KinasihanJana Data + LanggengKayohanaan Data + LuwihBagia Data + ManggihBagia Data + ManggihSuka Data + PatiningAmerta Data + Rahayu Data + SidhaKasobagian Data + Subagia Data + SukaKapanggih Data + SukaPinanggih Data + SukaRahayu Data + TininggalingSuka Data + WerdhiPutra Data + WerdhiSarwaMule Data +} + +func newEkaJalaRsi() EkaJalaRsi { + return EkaJalaRsi{ + BagnaMapasah: Data{0, "Bagna Mapasah"}, + BahuPutra: Data{1, "Bahu Putra"}, + BahuAstawa: Data{2, "Bahu Astawa"}, + BuatKingking: Data{3, "Buat Kingking"}, + BuatLara: Data{4, "Buat Lara"}, + BuatMerang: Data{5, "Buat Merang"}, + BuatSebet: Data{6, "Buat Sebet"}, + BuatSuka: Data{7, "Buat Suka"}, + DahatKingking: Data{8, "Dahat Kingking"}, + Kameranan: Data{9, "Kameranan"}, + Kamertaan: Data{10, "Kamertaan"}, + Kasobagian: Data{11, "Kasobagian"}, + KinasihanAmerta: Data{12, "Kinasihan Amerta"}, + KinasihanJana: Data{13, "Kinasihan Jana"}, + LanggengKayohanaan: Data{14, "Langgeng Kayohanaan"}, + LuwihBagia: Data{15, "Luwih Bagia"}, + ManggihBagia: Data{16, "Manggih Bagia"}, + ManggihSuka: Data{17, "Manggih Suka"}, + PatiningAmerta: Data{18, "Patining Amerta"}, + Rahayu: Data{19, "Rahayu"}, + SidhaKasobagian: Data{20, "Sidha Kasobagian"}, + Subagia: Data{21, "Subagia"}, + SukaKapanggih: Data{22, "Suka Kapanggih"}, + SukaPinanggih: Data{23, "Suka Pinanggih"}, + SukaRahayu: Data{24, "Suka Rahayu"}, + TininggalingSuka: Data{25, "Tininggaling Suka"}, + WerdhiPutra: Data{26, "Werdhi Putra"}, + WerdhiSarwaMule: Data{27, "Werdhi Sarwa Mule"}, + } +} + +func newEkaJalaRsiSlice() []Data { + data := newEkaJalaRsi() + return []Data{ + data.BagnaMapasah, + data.BahuPutra, + data.BahuAstawa, + data.BuatKingking, + data.BuatLara, + data.BuatMerang, + data.BuatSebet, + data.BuatSuka, + data.DahatKingking, + data.Kameranan, + data.Kamertaan, + data.Kasobagian, + data.KinasihanAmerta, + data.KinasihanJana, + data.LanggengKayohanaan, + data.LuwihBagia, + data.ManggihBagia, + data.ManggihSuka, + data.PatiningAmerta, + data.Rahayu, + data.SidhaKasobagian, + data.Subagia, + data.SukaKapanggih, + data.SukaPinanggih, + data.SukaRahayu, + data.TininggalingSuka, + data.WerdhiPutra, + data.WerdhiSarwaMule, + } +} diff --git a/eka_wara.go b/eka_wara.go new file mode 100644 index 0000000..b61e947 --- /dev/null +++ b/eka_wara.go @@ -0,0 +1,21 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type EkaWara struct { + Void Wara + Luang Wara +} + +func newEkaWara() EkaWara { + return EkaWara{ + Void: Wara{0, 0, ""}, + Luang: Wara{1, 1, "Luang"}, + } +} + +func newEkaWaraSlice() []Wara { + data := newEkaWara() + return []Wara{data.Void, data.Luang} +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..93752b7 --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module go.portalnesia.com/saka + +go 1.21 + +require github.com/golang-module/carbon v1.7.3 + +require ( + github.com/gobuffalo/envy v1.7.0 // indirect + github.com/gobuffalo/packd v0.3.0 // indirect + github.com/gobuffalo/packr v1.30.1 // indirect + github.com/joho/godotenv v1.3.0 // indirect + github.com/rogpeppe/go-internal v1.3.0 // indirect + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e41aa76 --- /dev/null +++ b/go.sum @@ -0,0 +1,77 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= +github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4= +github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= +github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg= +github.com/gobuffalo/packr v1.30.1/go.mod h1:ljMyFO2EcrnzsHsN99cvbq055Y9OhRrIaviy289eRuk= +github.com/gobuffalo/packr/v2 v2.5.1/go.mod h1:8f9c96ITobJlPzI44jj+4tHnEKNt0xXWSVlXRN9X1Iw= +github.com/golang-module/carbon v1.7.3 h1:p5mUZj7Tg62MblrkF7XEoxVPvhVs20N/kimqsZOQ+/U= +github.com/golang-module/carbon v1.7.3/go.mod h1:nUMnXq90Rv8a7h2+YOo2BGKS77Y0w/hMPm4/a8h19N8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190624180213-70d37148ca0c/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/ingkel.go b/ingkel.go new file mode 100644 index 0000000..da544d6 --- /dev/null +++ b/ingkel.go @@ -0,0 +1,29 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Ingkel struct { + Wong Data + Sato Data + Mina Data + Manuk Data + Taru Data + Buku Data +} + +func newIngkel() Ingkel { + return Ingkel{ + Wong: Data{0, "Wong"}, + Sato: Data{1, "Sato"}, + Mina: Data{2, "Mina"}, + Manuk: Data{3, "Manuk"}, + Taru: Data{4, "Taru"}, + Buku: Data{5, "Buku"}, + } +} + +func newIngkelSlice() []Data { + data := newIngkel() + return []Data{data.Wong, data.Sato, data.Mina, data.Manuk, data.Taru, data.Buku} +} diff --git a/jejapan.go b/jejapan.go new file mode 100644 index 0000000..35e5dfd --- /dev/null +++ b/jejapan.go @@ -0,0 +1,29 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Jejapan struct { + Mina Data + Taru Data + Sato Data + Patra Data + Wong Data + Paksi Data +} + +func newJejapan() Jejapan { + return Jejapan{ + Mina: Data{0, "Mina"}, + Taru: Data{1, "Taru"}, + Sato: Data{2, "Sato"}, + Patra: Data{3, "Patra"}, + Wong: Data{4, "Wong"}, + Paksi: Data{5, "Paksi"}, + } +} + +func newJejapanSlice() []Data { + data := newJejapan() + return []Data{data.Mina, data.Taru, data.Sato, data.Patra, data.Wong, data.Paksi} +} diff --git a/lintang.go b/lintang.go new file mode 100644 index 0000000..18206e3 --- /dev/null +++ b/lintang.go @@ -0,0 +1,123 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Lintang struct { + Gajah Data + Kiriman Data + JungSarat Data + AtiwaTiwa Data + SangkaTikel Data + BubuBolong Data + Sungenge Data + Uluku Data + Pedati Data + Kuda Data + GajahMina Data + Bade Data + Magelut Data + Pagelangan Data + KalaSungsang Data + Kukus Data + Asu Data + Kartika Data + Naga Data + AngsaAngrem Data + Panah Data + Patrem Data + Lembu Data + Depat Data + Tangis Data + SalahUkur Data + PerahuPegat Data + PuwuhAtarung Data + Lawean Data + Kelapa Data + Yuyu Data + Lumbung Data + Kumba Data + Udang Data + Begoong Data +} + +func newLintang() Lintang { + return Lintang{ + Gajah: Data{0, "Gajah"}, + Kiriman: Data{1, "Kiriman"}, + JungSarat: Data{2, "Jung Sarat"}, + AtiwaTiwa: Data{3, "Atiwa Tiwa"}, + SangkaTikel: Data{4, "Sangka Tikel"}, + BubuBolong: Data{5, "Bubu Bolong"}, + Sungenge: Data{6, "Sungenge"}, + Uluku: Data{7, "Uluku"}, + Pedati: Data{8, "Pedati"}, + Kuda: Data{9, "Kuda"}, + GajahMina: Data{10, "Gajah Mina"}, + Bade: Data{11, "Bade"}, + Magelut: Data{12, "Magelut"}, + Pagelangan: Data{13, "Pagelangan"}, + KalaSungsang: Data{14, "Kala Sungsang"}, + Kukus: Data{15, "Kukus"}, + Asu: Data{16, "Asu"}, + Kartika: Data{17, "Kartika"}, + Naga: Data{18, "Naga"}, + AngsaAngrem: Data{19, "Angsa Angrem"}, + Panah: Data{20, "Panah"}, + Patrem: Data{21, "Patrem"}, + Lembu: Data{22, "Lembu"}, + Depat: Data{23, "Depat"}, + Tangis: Data{24, "Tangis"}, + SalahUkur: Data{25, "Salah Ukur"}, + PerahuPegat: Data{26, "Perahu Pegat"}, + PuwuhAtarung: Data{27, "Puwuh Atarung"}, + Lawean: Data{28, "Lawean"}, + Kelapa: Data{29, "Kelapa"}, + Yuyu: Data{30, "Yuyu"}, + Lumbung: Data{31, "Lumbung"}, + Kumba: Data{32, "Kumba"}, + Udang: Data{33, "Udang"}, + Begoong: Data{34, "Begoong"}, + } +} + +func newLintangSlice() []Data { + data := newLintang() + return []Data{ + data.Gajah, + data.Kiriman, + data.JungSarat, + data.AtiwaTiwa, + data.SangkaTikel, + data.BubuBolong, + data.Sungenge, + data.Uluku, + data.Pedati, + data.Kuda, + data.GajahMina, + data.Bade, + data.Magelut, + data.Pagelangan, + data.KalaSungsang, + data.Kukus, + data.Asu, + data.Kartika, + data.Naga, + data.AngsaAngrem, + data.Panah, + data.Patrem, + data.Lembu, + data.Depat, + data.Tangis, + data.SalahUkur, + data.PerahuPegat, + data.PuwuhAtarung, + data.Lawean, + data.Kelapa, + data.Yuyu, + data.Lumbung, + data.Kumba, + data.Udang, + data.Begoong, + } +} diff --git a/panca_wara.go b/panca_wara.go new file mode 100644 index 0000000..9113e19 --- /dev/null +++ b/panca_wara.go @@ -0,0 +1,34 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type PancaWaraData struct { + ID int64 + Urip int64 + Kupih int64 + Name string +} + +type PancaWara struct { + Paing PancaWaraData + Pon PancaWaraData + Wage PancaWaraData + Kliwon PancaWaraData + Umanis PancaWaraData +} + +func newPancaWara() PancaWara { + return PancaWara{ + Paing: PancaWaraData{0, 9, 3, "Paing"}, + Pon: PancaWaraData{1, 7, 4, "Pon"}, + Wage: PancaWaraData{2, 4, 5, "Wage"}, + Kliwon: PancaWaraData{3, 8, 1, "Kliwon"}, + Umanis: PancaWaraData{4, 5, 2, "Umanis"}, + } +} + +func newPancaWaraSlice() []PancaWaraData { + data := newPancaWara() + return []PancaWaraData{data.Paing, data.Pon, data.Wage, data.Kliwon, data.Umanis} +} diff --git a/pansa_suda.go b/pansa_suda.go new file mode 100644 index 0000000..9d1443c --- /dev/null +++ b/pansa_suda.go @@ -0,0 +1,31 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type PancaSuda struct { + LebuKatiupAngin Data + WisesaSegara Data + TunggakSemi Data + SatriaWibawa Data + SumurSinaba Data + SatriaWirang Data + BumiKapetak Data +} + +func newPancaSuda() PancaSuda { + return PancaSuda{ + LebuKatiupAngin: Data{0, "Lebu Katiup Angin"}, + WisesaSegara: Data{1, "Wisesa Segara"}, + TunggakSemi: Data{2, "Tunggak Semi"}, + SatriaWibawa: Data{3, "Satria Wibawa"}, + SumurSinaba: Data{4, "Sumur Sinaba"}, + SatriaWirang: Data{5, "Satria Wirang"}, + BumiKapetak: Data{6, "Bumi Kapetak"}, + } +} + +func newPancaSudaSlice() []Data { + data := newPancaSuda() + return []Data{data.LebuKatiupAngin, data.WisesaSegara, data.TunggakSemi, data.SatriaWibawa, data.SumurSinaba, data.SatriaWirang, data.BumiKapetak} +} diff --git a/pararasan.go b/pararasan.go new file mode 100644 index 0000000..e2ff8d9 --- /dev/null +++ b/pararasan.go @@ -0,0 +1,48 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Pararasan struct { + LakuPanditaSakti Data + ArasTuding Data + ArasKembang Data + LakuBintang Data + LakuBulan Data + LakuSurya Data + LakuAir Data + LakuBumi Data + LakuApi Data + LakuAngin Data +} + +func newPararasan() Pararasan { + return Pararasan{ + LakuPanditaSakti: Data{0, "Laku Pandita Sakti"}, + ArasTuding: Data{1, "Aras Tuding"}, + ArasKembang: Data{2, "Aras Kembang"}, + LakuBintang: Data{3, "Laku Bintang"}, + LakuBulan: Data{4, "Laku Bulan"}, + LakuSurya: Data{5, "Laku Surya"}, + LakuAir: Data{6, "Laku Air"}, + LakuBumi: Data{7, "Laku Bumi"}, + LakuApi: Data{8, "Laku Api"}, + LakuAngin: Data{9, "Laku Angin"}, + } +} + +func newPararasanSlice() []Data { + data := newPararasan() + return []Data{ + data.LakuPanditaSakti, + data.ArasTuding, + data.ArasKembang, + data.LakuBintang, + data.LakuBulan, + data.LakuSurya, + data.LakuAir, + data.LakuBumi, + data.LakuApi, + data.LakuAngin, + } +} diff --git a/pivot.go b/pivot.go new file mode 100644 index 0000000..aed8a73 --- /dev/null +++ b/pivot.go @@ -0,0 +1,34 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import "github.com/golang-module/carbon" + +type PivotData struct { + Carbon carbon.Carbon + PawukonDay int64 + SasihDay int64 + NgunaratriDay int64 + Saka int64 + Sasih SasihData + IsNampihSasih bool +} + +type Pivot struct { + Pivot1971 PivotData + Pivot2000 PivotData +} + +func newPivot() Pivot { + + return Pivot{ + Pivot1971: PivotData{carbon.CreateFromDate(1971, 1, 27), 3, 0, 0, 1892, SasihData{6, 6, "Kapitu", nil}, false}, + Pivot2000: PivotData{carbon.CreateFromDate(2000, 1, 18), 86, 12, 0, 1921, SasihData{6, 6, "Kapitu", nil}, false}, + } +} + +// func newPivotSlice() []PivotData { +// data := newPivot() +// return []PivotData{data.Pivot1971, data.Pivot2000} +// } diff --git a/pratithi_samut_pada.go b/pratithi_samut_pada.go new file mode 100644 index 0000000..c819269 --- /dev/null +++ b/pratithi_samut_pada.go @@ -0,0 +1,54 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type PratithiSamutPada struct { + Tresna Data + Upadana Data + Bhawa Data + Jati Data + Jaramarana Data + Awidya Data + Saskara Data + Widnyana Data + Namarupa Data + Sadayatana Data + Separsa Data + Wedana Data +} + +func newPratithiSamutPada() PratithiSamutPada { + return PratithiSamutPada{ + Tresna: Data{0, "Tresna"}, + Upadana: Data{1, "Upadana"}, + Bhawa: Data{2, "Bhawa"}, + Jati: Data{3, "Jati"}, + Jaramarana: Data{4, "Jaramarana"}, + Awidya: Data{5, "Awidya"}, + Saskara: Data{6, "Saskara"}, + Widnyana: Data{7, "Widnyana"}, + Namarupa: Data{8, "Namarupa"}, + Sadayatana: Data{9, "Sadayatana"}, + Separsa: Data{10, "Separsa"}, + Wedana: Data{11, "Wedana"}, + } +} + +func newPratithiSamutPadaSlice() []Data { + data := newPratithiSamutPada() + return []Data{ + data.Tresna, + data.Upadana, + data.Bhawa, + data.Jati, + data.Jaramarana, + data.Awidya, + data.Saskara, + data.Widnyana, + data.Namarupa, + data.Sadayatana, + data.Separsa, + data.Wedana, + } +} diff --git a/rahinan.go b/rahinan.go new file mode 100644 index 0000000..6798da1 --- /dev/null +++ b/rahinan.go @@ -0,0 +1,223 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Rahinan struct { + SomaRibek Data + SabuhEmas Data + PagerWesi Data + TumpekLandep Data + TumpekUduh Data + SugihanJawa Data + SugihanBali Data + PenyekebanGalungan Data + PenyajanGalungan Data + PenampahanGalungan Data + Galungan Data + ManisGalungan Data + PemaridanGuru Data + Ulihan Data + PemacekanAgung Data + PenampahanKuningan Data + Kuningan Data + PegatUwakan Data + TumpekKandang Data + TumpekWayang Data + Saraswati Data + BanyuPinaruh Data + SiwaRatri Data + TawurAgungKasanga Data + Nyepi Data + NgembakGeni Data + BudaCemeng Data + AnggaraKasih Data + KajengKliwon Data + Purnama Data + Tilem Data +} + +func newRahinan() Rahinan { + return Rahinan{ + SomaRibek: Data{0, "Soma Ribek"}, + SabuhEmas: Data{1, "Sabuh Emas"}, + PagerWesi: Data{2, "Pager Wesi"}, + TumpekLandep: Data{3, "Tumpek Landep"}, + TumpekUduh: Data{4, "Tumpek Uduh"}, + SugihanJawa: Data{5, "Sugihan Jawa"}, + SugihanBali: Data{6, "Sugihan Bali"}, + PenyekebanGalungan: Data{7, "Penyekeban Galungan"}, + PenyajanGalungan: Data{8, "Penyajan Galungan"}, + PenampahanGalungan: Data{9, "Penampahan Galungan"}, + Galungan: Data{10, "Galungan"}, + ManisGalungan: Data{11, "Manis Galungan"}, + PemaridanGuru: Data{12, "Pemaridan Guru"}, + Ulihan: Data{13, "Ulihan"}, + PemacekanAgung: Data{14, "Pemacekan Agung"}, + PenampahanKuningan: Data{15, "Penampahan Kuningan"}, + Kuningan: Data{16, "Kuningan"}, + PegatUwakan: Data{17, "Pegat Uwakan"}, + TumpekKandang: Data{18, "Tumpek Kandang"}, + TumpekWayang: Data{19, "Tumpek Wayang"}, + Saraswati: Data{20, "Saraswati"}, + BanyuPinaruh: Data{21, "Banyu Pinaruh"}, + SiwaRatri: Data{22, "Siwa Ratri"}, + TawurAgungKasanga: Data{23, "Tawur Agung Kasanga"}, + Nyepi: Data{24, "Nyepi"}, + NgembakGeni: Data{25, "Ngembak Geni"}, + BudaCemeng: Data{26, "Buda Cemeng"}, + AnggaraKasih: Data{27, "Anggara Kasih"}, + KajengKliwon: Data{28, "Kajeng Kliwon"}, + Purnama: Data{29, "Purnama"}, + Tilem: Data{30, "Tilem"}, + } +} + +// func newRahinanSlice() []Data { +// data := newRahinan() +// return []Data{ +// data.SomaRibek, +// data.SabuhEmas, +// data.PagerWesi, +// data.TumpekLandep, +// data.TumpekUduh, +// data.SugihanJawa, +// data.SugihanBali, +// data.PenyekebanGalungan, +// data.PenyajanGalungan, +// data.PenampahanGalungan, +// data.Galungan, +// data.ManisGalungan, +// data.PemaridanGuru, +// data.Ulihan, +// data.PemacekanAgung, +// data.PenampahanKuningan, +// data.Kuningan, +// data.PegatUwakan, +// data.TumpekKandang, +// data.TumpekWayang, +// data.Saraswati, +// data.BanyuPinaruh, +// data.SiwaRatri, +// data.TawurAgungKasanga, +// data.Nyepi, +// data.NgembakGeni, +// data.BudaCemeng, +// data.AnggaraKasih, +// data.KajengKliwon, +// data.Purnama, +// data.Tilem, +// } +// } + +/* +Get Rahinan for Saka instance +*/ +func (s *Saka) Rahinan() []Data { + if s.rahinan == nil { + arr := []Data{} + + if s.TriWara == Enum.TriWara.Kajeng && s.PancaWara == Enum.PancaWara.Kliwon { + arr = append(arr, Enum.Rahinan.KajengKliwon) + } + + if s.SaptaWara == Enum.SaptaWara.Anggara && s.PancaWara == Enum.PancaWara.Kliwon { + arr = append(arr, Enum.Rahinan.AnggaraKasih) + } else if s.SaptaWara == Enum.SaptaWara.Buda && s.PancaWara == Enum.PancaWara.Wage { + arr = append(arr, Enum.Rahinan.BudaCemeng) + } + + if s.Wuku == Enum.Wuku.Sinta { + if s.SaptaWara == Enum.SaptaWara.Redite { + arr = append(arr, Enum.Rahinan.BanyuPinaruh) + } else if s.SaptaWara == Enum.SaptaWara.Soma { + arr = append(arr, Enum.Rahinan.SomaRibek) + } else if s.SaptaWara == Enum.SaptaWara.Anggara { + arr = append(arr, Enum.Rahinan.SabuhEmas) + } else if s.SaptaWara == Enum.SaptaWara.Buda { + arr = append(arr, Enum.Rahinan.PagerWesi) + } + } else if s.Wuku == Enum.Wuku.Landep { + if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.TumpekLandep) + } + } else if s.Wuku == Enum.Wuku.Wariga { + if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.TumpekUduh) + } + } else if s.Wuku == Enum.Wuku.Sungsang { + if s.SaptaWara == Enum.SaptaWara.Wraspati { + arr = append(arr, Enum.Rahinan.SugihanJawa) + } else if s.SaptaWara == Enum.SaptaWara.Sukra { + arr = append(arr, Enum.Rahinan.SugihanBali) + } + } else if s.Wuku == Enum.Wuku.Dungulan { + if s.SaptaWara == Enum.SaptaWara.Redite { + arr = append(arr, Enum.Rahinan.PenyekebanGalungan) + } else if s.SaptaWara == Enum.SaptaWara.Soma { + arr = append(arr, Enum.Rahinan.PenyajanGalungan) + } else if s.SaptaWara == Enum.SaptaWara.Anggara { + arr = append(arr, Enum.Rahinan.PenampahanGalungan) + } else if s.SaptaWara == Enum.SaptaWara.Buda { + arr = append(arr, Enum.Rahinan.Galungan) + } else if s.SaptaWara == Enum.SaptaWara.Wraspati { + arr = append(arr, Enum.Rahinan.ManisGalungan) + } else if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.PemaridanGuru) + } + } else if s.Wuku == Enum.Wuku.Kuningan { + if s.SaptaWara == Enum.SaptaWara.Redite { + arr = append(arr, Enum.Rahinan.Ulihan) + } else if s.SaptaWara == Enum.SaptaWara.Soma { + arr = append(arr, Enum.Rahinan.PemacekanAgung) + } else if s.SaptaWara == Enum.SaptaWara.Sukra { + arr = append(arr, Enum.Rahinan.PenampahanKuningan) + } else if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.Kuningan) + } + } else if s.Wuku == Enum.Wuku.Pahang { + if s.SaptaWara == Enum.SaptaWara.Buda { + arr = append(arr, Enum.Rahinan.PegatUwakan) + } + } else if s.Wuku == Enum.Wuku.Uye { + if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.TumpekKandang) + } + } else if s.Wuku == Enum.Wuku.Wayang { + if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.TumpekWayang) + } + } else if s.Wuku == Enum.Wuku.Watugunung { + if s.SaptaWara == Enum.SaptaWara.Saniscara { + arr = append(arr, Enum.Rahinan.Saraswati) + } + } + + temp := s.Carbon + + n1Day := New(temp.AddDay()) + b1Day := New(temp.SubDay()) + b2Day := New(temp.SubDays(2)) + + // fmt.Println(s.Carbon.ToDateString(), b1Day.Saka, s.Saka) + if n1Day.Sasih == Enum.Sasih.Kapitu && n1Day.SasihDayInfo == Enum.SasihDayInfo.Tilem { + arr = append(arr, Enum.Rahinan.SiwaRatri) + } else if s.Saka < n1Day.Saka { + arr = append(arr, Enum.Rahinan.TawurAgungKasanga) + } else if b1Day.Saka < s.Saka { + arr = append(arr, Enum.Rahinan.Nyepi) + } else if b2Day.Saka < s.Saka && b1Day.Saka == s.Saka { + arr = append(arr, Enum.Rahinan.NgembakGeni) + } + + if s.SasihDayInfo == Enum.SasihDayInfo.Purnama { + arr = append(arr, Enum.Rahinan.Purnama) + } else if s.SasihDayInfo == Enum.SasihDayInfo.Tilem { + arr = append(arr, Enum.Rahinan.Tilem) + } + + s.rahinan = &arr + } + + return *s.rahinan +} diff --git a/rakam.go b/rakam.go new file mode 100644 index 0000000..f47a7d3 --- /dev/null +++ b/rakam.go @@ -0,0 +1,36 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Rakam struct { + NujuPati Data + KalaTinantang Data + DemangKadhuruwan Data + SanggarWaringin Data + MantriSinaroja Data + MacanKatawan Data +} + +func newRakam() Rakam { + return Rakam{ + NujuPati: Data{0, "Nuju Pati"}, + KalaTinantang: Data{1, "Kala Tinantang"}, + DemangKadhuruwan: Data{2, "Demang Kadhuruwan"}, + SanggarWaringin: Data{3, "Sanggar Waringin"}, + MantriSinaroja: Data{4, "Mantri Sinaroja"}, + MacanKatawan: Data{5, "Macan Katawan"}, + } +} + +func newRakamSlice() []Data { + data := newRakam() + return []Data{ + data.NujuPati, + data.KalaTinantang, + data.DemangKadhuruwan, + data.SanggarWaringin, + data.MantriSinaroja, + data.MacanKatawan, + } +} diff --git a/range.go b/range.go new file mode 100644 index 0000000..95d24b2 --- /dev/null +++ b/range.go @@ -0,0 +1,85 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import ( + "errors" + + "github.com/golang-module/carbon" +) + +type SakaRangeDate struct { + Saka Saka // Saka instance + Rahinan []Data // Array of Rahinan +} + +type SakaRange struct { + data []SakaRangeDate +} + +/* +Create new Saka range instance + +Accept any format of date. For example + + - 2023-08-03 // valid date string + - time.Now() // time package + - carbon.Now() // carbon package +*/ +func NewRange(date1 interface{}, date2 interface{}) (*SakaRange, error) { + if date1 == nil || date2 == nil { + return nil, errors.New("date1 and date2 cannot be nil") + } + + d1 := getCarbon(date1) + d2 := getCarbon(date2) + + rangeDate := d1.DiffAbsInDays(d2) + 1 + + if rangeDate > 7 { + return nil, errors.New("maximum range is 7 days") + } + + tmpRange := d1.DiffInDays(d2) + var date carbon.Carbon + + if tmpRange < 0 { + date = d2 + } else { + date = d1 + } + + response := []SakaRangeDate{} + + for i := int64(0); i < rangeDate; i++ { + sk := New(date) + rahinan := sk.Rahinan() + response = append(response, SakaRangeDate{Saka: *sk, Rahinan: rahinan}) + date = date.AddDay() + } + + sakaRange := SakaRange{ + data: response, + } + + return &sakaRange, nil +} + +/* +List all Rahinan in the range by date +*/ +func (s *SakaRange) ListByDate() []SakaRangeDate { + return s.data +} + +// List all Rahinan in the range +func (s *SakaRange) ListAllRahinan() []Data { + var response []Data + + for _, v := range s.data { + response = append(response, v.Rahinan...) + } + + return response +} diff --git a/range_test.go b/range_test.go new file mode 100644 index 0000000..65aaebb --- /dev/null +++ b/range_test.go @@ -0,0 +1,103 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import ( + "testing" + + "github.com/golang-module/carbon" +) + +func TestDateNil(t *testing.T) { + d1 := carbon.CreateFromDate(2023, 8, 27) + + _, err := NewRange(nil, d1) + if err == nil { + t.Error("Error not shown") + } else if err.Error() != "date1 and date2 cannot be nil" { + t.Error("Error message invalid") + } +} + +func TestReverseDateRange(t *testing.T) { + d1 := carbon.CreateFromDate(2023, 8, 27) + d2 := carbon.CreateFromDate(2023, 8, 31) + + saka, err := NewRange(d2, d1) + if err != nil { + t.Error(err) + } + + rahinan := saka.ListAllRahinan() + if len(rahinan) != 2 { + t.Error("Rahinan failed") + } +} + +func TestRangeListAllRahinan(t *testing.T) { + d1 := carbon.CreateFromDate(2023, 8, 27) + d2 := carbon.CreateFromDate(2023, 8, 31) + + saka, err := NewRange(d1, d2) + if err != nil { + t.Error(err) + } + + rahinan := saka.ListAllRahinan() + if len(rahinan) != 2 { + t.Error("Rahinan failed") + } + + saka, err = NewRange(d2, d1) + if err != nil { + t.Error(err) + } + + rahinan = saka.ListAllRahinan() + if len(rahinan) != 2 { + t.Error("Rahinan failed") + } +} + +func TestRangeListByDate(t *testing.T) { + d1 := carbon.CreateFromDate(2023, 8, 27) + d2 := carbon.CreateFromDate(2023, 8, 31) + + saka, err := NewRange(d1, d2) + if err != nil { + t.Error(err) + } + + rahinan := saka.ListByDate() + for i, r := range rahinan { + if i == 0 { + if r.Saka.Carbon.DayOfMonth() != d1.DayOfMonth() { + t.Errorf("First date not same: %s", r.Saka.Carbon.ToString()) + } + if r.Rahinan[0].ID != 28 { + t.Errorf("First rahinan not same: %s", r.Rahinan[0].Name) + } + } + if i == len(rahinan)-1 { + if r.Saka.Carbon.DayOfMonth() != d2.DayOfMonth() { + t.Errorf("Last date not same: %s", r.Saka.Carbon.ToString()) + } + if r.Rahinan[0].ID != 29 { + t.Errorf("Last rahinan not same: %s", r.Rahinan[0].Name) + } + } + } +} + +func TestMaxRangeError(t *testing.T) { + d1 := carbon.CreateFromDate(2023, 8, 5) + d2 := carbon.CreateFromDate(2023, 8, 31) + + _, err := NewRange(d1, d2) + if err == nil { + t.Error("Error not shown") + } else if err.Error() != "maximum range is 7 days" { + t.Error("Error message invalid") + } +} diff --git a/sad_wara.go b/sad_wara.go new file mode 100644 index 0000000..698dfec --- /dev/null +++ b/sad_wara.go @@ -0,0 +1,29 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type SadWara struct { + Tungleh Wara + Aryang Wara + Urukung Wara + Paniron Wara + Was Wara + Maulu Wara +} + +func newSadWara() SadWara { + return SadWara{ + Tungleh: Wara{0, 7, "Tungleh"}, + Aryang: Wara{1, 6, "Aryang"}, + Urukung: Wara{2, 5, "Urukung"}, + Paniron: Wara{3, 8, "Paniron"}, + Was: Wara{4, 9, "Was"}, + Maulu: Wara{5, 3, "Maulu"}, + } +} + +func newSadWaraSlice() []Wara { + data := newSadWara() + return []Wara{data.Tungleh, data.Aryang, data.Urukung, data.Paniron, data.Was, data.Maulu} +} diff --git a/saka.go b/saka.go new file mode 100644 index 0000000..8170836 --- /dev/null +++ b/saka.go @@ -0,0 +1,167 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import ( + "math" + + "github.com/golang-module/carbon" +) + +type enumData struct { + AstaWara AstaWara + CaturWara CaturWara + DasaWara DasaWara + DwiWara DwiWara + EkaJalaRsi EkaJalaRsi + EkaWara EkaWara + Ingkel Ingkel + Jejapan Jejapan + Lintang Lintang + PancaWara PancaWara + PancaSuda PancaSuda + Pararasan Pararasan + Pivot Pivot + PratithiSamutPada PratithiSamutPada + Rahinan Rahinan + Rakam Rakam + SadWara SadWara + SangaWara SangaWara + SaptaWara SaptaWara + Sasih Sasih + SasihDayInfo SasihDayInfo + TriWara TriWara + WatekAlit WatekAlit + WatekMadya WatekMadya + Wuku Wuku +} + +var Enum = enumData{ + AstaWara: newAstaWara(), + CaturWara: newCaturWara(), + DasaWara: newDasaWara(), + DwiWara: newDwiWara(), + EkaJalaRsi: newEkaJalaRsi(), + EkaWara: newEkaWara(), + Ingkel: newIngkel(), + Jejapan: newJejapan(), + Lintang: newLintang(), + PancaWara: newPancaWara(), + PancaSuda: newPancaSuda(), + Pararasan: newPararasan(), + Pivot: newPivot(), + PratithiSamutPada: newPratithiSamutPada(), + Rahinan: newRahinan(), + Rakam: newRakam(), + SadWara: newSadWara(), + SangaWara: newSangaWara(), + SaptaWara: newSaptaWara(), + Sasih: newSasih(), + SasihDayInfo: newSasihDayInfo(), + TriWara: newTriWara(), + WatekAlit: newWatekAlit(), + WatekMadya: newWatekMadya(), + Wuku: newWuku(), +} + +type Saka struct { + Carbon carbon.Carbon + Wuku WukuData + TriWara Wara + PancaWara PancaWaraData + SadWara Wara + SaptaWara SaptaWaraData + Jejapan Data + Lintang Data + PancaSuda Data + Rakam Data + EkaJalaRsi Data + Ingkel Data + EkaWara Wara + DwiWara Wara + DasaWara Wara + WatekAlit Data + WatekMadya Data + Pararasan Data + CaturWara Wara + AstaWara Wara + SangaWara Wara + Saka int64 + Sasih SasihData + SasihDayInfo SasihDayInfoData + SasihDay []int64 // 2 or one array of int64 + PratithiSamutPada Data + + rahinan *[]Data +} + +/* +Create new Saka instance + +Accept any format of date. For example + + - 2023-08-03 // valid date string + - time.Now() // time package + - carbon.Now() // carbon package + +Default: now +*/ +func New(date_arg ...interface{}) *Saka { + saka := Saka{} + + date := getCarbon(date_arg...) + saka.Carbon = date + + pivot := getBestPivot(date) + pawukonDay := getPawukonDay(pivot, date) + + saka.Wuku = newWukuSlice()[int64(math.Floor(float64(pawukonDay)/7))] + saka.TriWara = newTwiWaraSlice()[pawukonDay%3] + saka.PancaWara = newPancaWaraSlice()[pawukonDay%5] + saka.SadWara = newSadWaraSlice()[pawukonDay%6] + saka.SaptaWara = newSaptaWaraSlice()[pawukonDay%7] + saka.Jejapan = newJejapanSlice()[pawukonDay%6] + saka.Lintang = newLintangSlice()[pawukonDay%35] + saka.PancaSuda = newPancaSudaSlice()[(saka.SaptaWara.KertaAji+saka.PancaWara.Urip)%7] + saka.Rakam = newRakamSlice()[(saka.SaptaWara.Kupih+saka.PancaWara.Kupih)%6] + saka.EkaJalaRsi = newEkaJalaRsiSlice()[c_ekajalarsislice[pawukonDay]] + saka.Ingkel = newIngkelSlice()[saka.Wuku.ID%6] + + urip := saka.PancaWara.Urip + saka.SaptaWara.Urip + saka.EkaWara = newEkaWaraSlice()[urip%2] + saka.DwiWara = newDwiWaraSlice()[urip%2] + saka.DasaWara = newDasaWaraSlice()[urip%10] + saka.WatekAlit = newWatekAlitSlice()[urip%4] + saka.WatekMadya = newWatekMadyaSlice()[urip%5] + saka.Pararasan = newPararasanSlice()[urip%10] + saka.CaturWara = getCaturwara(pawukonDay) + saka.AstaWara = getAstawara(pawukonDay) + saka.SangaWara = getSangawara(pawukonDay) + + resSasih := getSasihInfo(pivot, date) + resSasihDay := getSasihDay(pivot, date) + + saka.Saka = resSasih[0] + saka.Sasih = getSasih(resSasih) + saka.SasihDayInfo = getSasihDayInfo(resSasihDay, saka.Sasih, saka.Saka) + + var sasihDay []int64 + if resSasihDay[2] == 1 { + sasihDay = make([]int64, 2) + sasihDay[0] = resSasihDay[0] + if resSasihDay[0] == 15 { + sasihDay[1] = 1 + } else { + sasihDay[1] = resSasihDay[0] + 1 + } + } else { + sasihDay = make([]int64, 1) + sasihDay[0] = resSasihDay[0] + } + saka.SasihDay = sasihDay + + saka.PratithiSamutPada = getPratithiSamutPada(saka.SasihDay, saka.SasihDayInfo, saka.Sasih, date) + + return &saka +} diff --git a/saka_test.go b/saka_test.go new file mode 100644 index 0000000..ee09f50 --- /dev/null +++ b/saka_test.go @@ -0,0 +1,165 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import ( + "fmt" + "testing" + "time" + + "github.com/golang-module/carbon" +) + +func TestEqual(t *testing.T) { + saka := New() + saka2 := New() + + if saka.PancaWara != saka2.PancaWara { + t.Errorf("Saka and saka2 should be equal %s", saka.PancaWara.Name) + } +} + +func TestInvalidFormat(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Error("Saka must panic") + } + }() + _ = New("Invalid format") + t.Error("Saka must panic") +} + +func TestStringFormat(t *testing.T) { + calendar := New("2023-03-22") + nyepi := false + rangeDay := []Data{} +checkNyepi: + for _, r := range calendar.Rahinan() { + rangeDay = append(rangeDay, r) + if r == Enum.Rahinan.Nyepi { + nyepi = true + break checkNyepi + } + } + + if !nyepi { + t.Errorf("This date must nyepi, get %+v", rangeDay) + } +} + +func TestBytesFormat(t *testing.T) { + calendar := New([]byte("2023-03-22")) + nyepi := false + rangeDay := []Data{} +checkNyepi: + for _, r := range calendar.Rahinan() { + rangeDay = append(rangeDay, r) + if r == Enum.Rahinan.Nyepi { + nyepi = true + break checkNyepi + } + } + + if !nyepi { + t.Errorf("This date must nyepi, get %+v", rangeDay) + } +} + +func TestTimeFormat(t *testing.T) { + loc, err := time.LoadLocation("Asia/Jakarta") + if err != nil { + t.Error(err) + } + calendar := New(time.Date(2023, 3, 22, 0, 0, 0, 0, loc)) + nyepi := false + rangeDay := []Data{} +checkNyepi: + for _, r := range calendar.Rahinan() { + rangeDay = append(rangeDay, r) + if r == Enum.Rahinan.Nyepi { + nyepi = true + break checkNyepi + } + } + + if !nyepi { + t.Errorf("This date must nyepi, get %+v", rangeDay) + } +} + +func TestNyepi(t *testing.T) { + calendar := New(carbon.CreateFromDate(2023, 3, 22)) + nyepi := false + +checkNyepi: + for _, r := range calendar.Rahinan() { + if r == Enum.Rahinan.Nyepi { + + nyepi = true + break checkNyepi + } + } + + if !nyepi { + t.Error("This date must nyepi") + } + fmt.Printf("Nyepi saka %d\n", calendar.Saka) +} + +func TestSiwaratri(t *testing.T) { + calendar := New(carbon.CreateFromDate(2023, 1, 20)) + + isTrue := false + +check: + for _, r := range calendar.Rahinan() { + if r == Enum.Rahinan.SiwaRatri { + + isTrue = true + break check + } + } + + if !isTrue { + t.Error("This date must siwaratri") + } +} + +func TestGalungan(t *testing.T) { + calendar := New(carbon.CreateFromDate(2023, 8, 2)) + + isTrue := false + +check: + for _, r := range calendar.Rahinan() { + if r == Enum.Rahinan.Galungan { + + isTrue = true + break check + } + } + + if !isTrue { + t.Error("This date must galungan") + } +} + +func TestKuningan(t *testing.T) { + calendar := New(carbon.CreateFromDate(2023, 8, 12)) + + isTrue := false + +check: + for _, r := range calendar.Rahinan() { + if r == Enum.Rahinan.Kuningan { + + isTrue = true + break check + } + } + + if !isTrue { + t.Error("This date must kuningan") + } +} diff --git a/sanga_wara.go b/sanga_wara.go new file mode 100644 index 0000000..8e61e9e --- /dev/null +++ b/sanga_wara.go @@ -0,0 +1,45 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type SangaWara struct { + Dangu Wara + Jangur Wara + Gigis Wara + Nohan Wara + Ogan Wara + Erangan Wara + Urungan Wara + Tulus Wara + Dadi Wara +} + +func newSangaWara() SangaWara { + return SangaWara{ + Dangu: Wara{0, 5, "Dangu"}, + Jangur: Wara{1, 8, "Jangur"}, + Gigis: Wara{2, 9, "Gigis"}, + Nohan: Wara{3, 3, "Nohan"}, + Ogan: Wara{4, 7, "Ogan"}, + Erangan: Wara{5, 1, "Erangan"}, + Urungan: Wara{6, 4, "Urungan"}, + Tulus: Wara{7, 6, "Tulus"}, + Dadi: Wara{8, 8, "Dadi"}, + } +} + +func newSangaWaraSlice() []Wara { + data := newSangaWara() + return []Wara{ + data.Dangu, + data.Jangur, + data.Gigis, + data.Nohan, + data.Ogan, + data.Erangan, + data.Urungan, + data.Tulus, + data.Dadi, + } +} diff --git a/sapta_wara.go b/sapta_wara.go new file mode 100644 index 0000000..3a0a5ab --- /dev/null +++ b/sapta_wara.go @@ -0,0 +1,39 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type SaptaWaraData struct { + ID int64 + Urip int64 + KertaAji int64 + Kupih int64 + Name string +} + +type SaptaWara struct { + Redite SaptaWaraData + Soma SaptaWaraData + Anggara SaptaWaraData + Buda SaptaWaraData + Wraspati SaptaWaraData + Sukra SaptaWaraData + Saniscara SaptaWaraData +} + +func newSaptaWara() SaptaWara { + return SaptaWara{ + Redite: SaptaWaraData{0, 5, 6, 3, "Redite"}, + Soma: SaptaWaraData{1, 4, 4, 4, "Soma"}, + Anggara: SaptaWaraData{2, 3, 3, 5, "Anggara"}, + Buda: SaptaWaraData{3, 7, 6, 6, "Buda"}, + Wraspati: SaptaWaraData{4, 8, 5, 7, "Wraspati"}, + Sukra: SaptaWaraData{5, 6, 7, 1, "Sukra"}, + Saniscara: SaptaWaraData{6, 9, 8, 2, "Saniscara"}, + } +} + +func newSaptaWaraSlice() []SaptaWaraData { + data := newSaptaWara() + return []SaptaWaraData{data.Redite, data.Soma, data.Anggara, data.Buda, data.Wraspati, data.Sukra, data.Saniscara} +} diff --git a/sasih.go b/sasih.go new file mode 100644 index 0000000..b867866 --- /dev/null +++ b/sasih.go @@ -0,0 +1,134 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type SasihData struct { + ID int64 + RefID int64 + Name string + ref *SasihData +} + +func (s SasihData) Reference() SasihData { + if s.ref == nil { + temp := newSasihSlice()[s.RefID] + s.ref = &temp + } + return *s.ref +} + +type Sasih struct { + Kasa SasihData + Karo SasihData + Katiga SasihData + Kapat SasihData + Kalima SasihData + Kanem SasihData + Kapitu SasihData + Kawolu SasihData + Kasanga SasihData + Kadasa SasihData + Destha SasihData + Sadha SasihData + MalaDestha SasihData + MalaSadha SasihData + NampihDestha SasihData + NampihKatiga SasihData + NampihKasa SasihData + NampihKadasa SasihData + NampihKaro SasihData + NampihSadha SasihData +} + +type SasihDayInfoData struct { + ID int64 + RefID int64 + Name string + ref *SasihDayInfoData +} + +func (s SasihDayInfoData) Reference() SasihDayInfoData { + if s.ref == nil { + temp := newSasihDayInfoSlice()[s.RefID] + s.ref = &temp + } + return *s.ref +} + +type SasihDayInfo struct { + Penanggal SasihDayInfoData + Pangelong SasihDayInfoData + Purnama SasihDayInfoData + Tilem SasihDayInfoData +} + +func newSasih() Sasih { + return Sasih{ + Kasa: SasihData{0, 0, "Kasa", nil}, + Karo: SasihData{1, 1, "Karo", nil}, + Katiga: SasihData{2, 2, "Katiga", nil}, + Kapat: SasihData{3, 3, "Kapat", nil}, + Kalima: SasihData{4, 4, "Kalima", nil}, + Kanem: SasihData{5, 5, "Kanem", nil}, + Kapitu: SasihData{6, 6, "Kapitu", nil}, + Kawolu: SasihData{7, 7, "Kawolu", nil}, + Kasanga: SasihData{8, 8, "Kasanga", nil}, + Kadasa: SasihData{9, 9, "Kadasa", nil}, + Destha: SasihData{10, 10, "Destha", nil}, + Sadha: SasihData{11, 11, "Sadha", nil}, + MalaDestha: SasihData{12, 10, "Mala Destha", nil}, + MalaSadha: SasihData{13, 11, "Mala Sadha", nil}, + NampihDestha: SasihData{14, 10, "Nampih Destha", nil}, + NampihKatiga: SasihData{15, 2, "Nampih Katiga", nil}, + NampihKasa: SasihData{16, 0, "Nampih Kasa", nil}, + NampihKadasa: SasihData{17, 9, "Nampih Kadasa", nil}, + NampihKaro: SasihData{18, 1, "Nampih Karo", nil}, + NampihSadha: SasihData{19, 11, "Nampih Sadha", nil}, + } +} + +func newSasihDayInfo() SasihDayInfo { + return SasihDayInfo{ + Penanggal: SasihDayInfoData{0, 0, "Penanggal", nil}, + Pangelong: SasihDayInfoData{1, 1, "Pangelong", nil}, + Purnama: SasihDayInfoData{2, 0, "Purnama", nil}, + Tilem: SasihDayInfoData{3, 1, "Tilem", nil}, + } +} + +func newSasihSlice() []SasihData { + data := newSasih() + return []SasihData{ + data.Kasa, + data.Karo, + data.Katiga, + data.Kapat, + data.Kalima, + data.Kanem, + data.Kapitu, + data.Kawolu, + data.Kasanga, + data.Kadasa, + data.Destha, + data.Sadha, + data.MalaDestha, + data.MalaSadha, + data.NampihDestha, + data.NampihKatiga, + data.NampihKasa, + data.NampihKadasa, + data.NampihKaro, + data.NampihSadha, + } +} + +func newSasihDayInfoSlice() []SasihDayInfoData { + data := newSasihDayInfo() + return []SasihDayInfoData{ + data.Penanggal, + data.Pangelong, + data.Purnama, + data.Tilem, + } +} diff --git a/struct.go b/struct.go new file mode 100644 index 0000000..be006a1 --- /dev/null +++ b/struct.go @@ -0,0 +1,15 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type Wara struct { + ID int64 + Urip int64 + Name string +} + +type Data struct { + ID int64 + Name string +} diff --git a/twi_wara.go b/twi_wara.go new file mode 100644 index 0000000..609fef6 --- /dev/null +++ b/twi_wara.go @@ -0,0 +1,23 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type TriWara struct { + Pasah Wara + Beteng Wara + Kajeng Wara +} + +func newTriWara() TriWara { + return TriWara{ + Pasah: Wara{0, 9, "Pasag"}, + Beteng: Wara{1, 4, "Beteng"}, + Kajeng: Wara{2, 7, "Kajeng"}, + } +} + +func newTwiWaraSlice() []Wara { + data := newTriWara() + return []Wara{data.Pasah, data.Beteng, data.Kajeng} +} diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..9b27238 --- /dev/null +++ b/utils.go @@ -0,0 +1,349 @@ +/* +Copyright © Portalnesia +*/ +package saka + +import ( + "errors" + "math" + "time" + + "github.com/golang-module/carbon" +) + +const ( + c_day_pawukon int64 = 210 + c_day_ngunaratri int64 = 63 +) + +var pangalantakaPaing = carbon.CreateFromDate(2000, 1, 6) +var skStart = carbon.CreateFromDate(1993, 1, 24) +var skEnd = carbon.CreateFromDate(2003, 1, 3) + +var c_ekajalarsislice []int = []int{23, 7, 17, 7, 23, 23, 17, 9, 7, 13, 26, 24, 23, 20, 13, 7, 13, 25, 19, 6, 2, + 14, 26, 17, 20, 25, 22, 0, 10, 6, 15, 23, 7, 17, 23, 17, 25, 5, 23, 2, 2, 2, 12, 12, 5, 14, 12, 26, 26, 1, + 23, 23, 15, 25, 15, 6, 9, 25, 18, 25, 11, 15, 21, 25, 25, 12, 0, 17, 13, 0, 15, 23, 12, 7, 16, 25, 18, 24, + 12, 12, 6, 7, 6, 26, 7, 6, 12, 7, 25, 2, 12, 25, 25, 14, 15, 26, 7, 12, 20, 7, 6, 25, 25, 6, 13, 25, 17, 13, + 23, 6, 26, 20, 25, 25, 23, 7, 18, 18, 17, 7, 17, 7, 5, 26, 17, 6, 9, 12, 12, 13, 25, 18, 18, 6, 2, 25, 25, + 2, 25, 17, 20, 14, 27, 23, 17, 8, 25, 17, 6, 17, 7, 3, 15, 18, 25, 2, 7, 13, 25, 20, 7, 15, 15, 23, 7, 8, + 24, 2, 12, 9, 24, 24, 17, 24, 20, 7, 12, 12, 14, 18, 25, 20, 5, 18, 5, 20, 26, 12, 23, 18, 17, 17, 25, 15, + 2, 24, 4, 2, 23, 25, 18, 25, 20, 14, 4, 2, 25, 7, 25, 17} + +func getCarbon(argument ...interface{}) carbon.Carbon { + var data carbon.Carbon + + if len(argument) == 0 { + data = carbon.Now() + } else if len(argument) > 0 { + switch v := argument[0].(type) { + case string: + data = carbon.Parse(v) + case carbon.Carbon: + data = v + case []byte: + data = carbon.Parse(string(v)) + case time.Time: + data = carbon.FromStdTime(v) + default: + + } + } + if !data.IsValid() { + panic(errors.New("invalid date")) + } + now := carbon.CreateFromDate(data.Year(), data.Month(), data.DayOfMonth()) + return now +} + +func getBestPivot(carbon carbon.Carbon) PivotData { + if pangalantakaPaing.DiffInDays(carbon) < 0 { + return Enum.Pivot.Pivot1971 + } + return Enum.Pivot.Pivot2000 +} + +func mod(a int64, b int64) int64 { + return ((a % b) + b) % b +} + +func delta(a carbon.Carbon, b carbon.Carbon) int64 { + return a.DiffInDays(b) +} + +func getPawukonDay(pivot PivotData, date carbon.Carbon) int64 { + return mod(int64(pivot.PawukonDay)+delta(pivot.Carbon, date), c_day_pawukon) +} + +func getCaturwara(pawukonDay int64) Wara { + caturwara := newCaturWaraSlice() + if pawukonDay < 71 { + return caturwara[pawukonDay%4] + } else if pawukonDay > 72 { + return caturwara[(pawukonDay-2)%4] + } + return Enum.CaturWara.Jaya +} + +func getAstawara(pawukonDay int64) Wara { + astawara := newAstaWaraSlice() + if pawukonDay < 71 { + return astawara[pawukonDay%8] + } else if pawukonDay > 72 { + return astawara[(pawukonDay-2)%8] + } + return Enum.AstaWara.Kala +} + +func getSangawara(pawukonDay int64) Wara { + if pawukonDay > 3 { + return newSangaWaraSlice()[(pawukonDay-3)%9] + } + return Enum.SangaWara.Dangu +} + +func getSasihInfo(pivot PivotData, date carbon.Carbon) []int64 { + res := make([]int64, 3) + pTime := pivot.Carbon + dayDiff := delta(pTime, date) + daySkip := int64(math.Ceil(float64(dayDiff) / float64(c_day_ngunaratri))) + dayTotal := pivot.SasihDay + dayDiff + daySkip + + pivotOffset := int64(1) + if pivot.SasihDay == 0 && pivot.NgunaratriDay == 0 { + pivotOffset = 0 + } + + totalSasih := int64(math.Ceil(float64(dayTotal)/30)) - pivotOffset + + currentSasih := pivot.Sasih.ID + currentSaka := pivot.Saka + if currentSasih == Enum.Sasih.Kadasa.ID { + currentSaka = pivot.Saka - 1 + } + nampihCount := 0 + if pivot.IsNampihSasih { + nampihCount = 1 + } + inSK := pTime.BetweenIncludedStart(skStart, skEnd) + // inSK := false + // if skStart.DiffInDays(pTime) >= 0 && skEnd.DiffInDays(pTime) < 0 { + // inSK = true + // } + + for totalSasih != 0 { + if dayDiff >= 0 { + if nampihCount == 0 || nampihCount == 2 { + nampihCount = 0 + currentSasih = mod(currentSasih+1, 12) + } + totalSasih = totalSasih - 1 + + if currentSasih == Enum.Sasih.Kadasa.ID && nampihCount == 0 { + currentSaka = currentSaka + 1 + } + + if currentSasih == Enum.Sasih.Kawolu.ID && currentSaka == 1914 { + inSK = true + } else if currentSasih == Enum.Sasih.Kawolu.ID && currentSaka == 1924 { + inSK = false + } + } else { + if nampihCount == 0 || nampihCount == 2 { + nampihCount = 0 + currentSasih = mod(currentSasih-1, 12) + } + + totalSasih = totalSasih + 1 + + if currentSasih == Enum.Sasih.Kasanga.ID && nampihCount == 0 { + currentSaka = currentSaka - 1 + } + + if currentSasih == Enum.Sasih.Kapitu.ID && currentSaka == 1914 { + inSK = false + } else if currentSasih == Enum.Sasih.Kapitu.ID && currentSaka == 1924 { + inSK = true + } + } + + switch temp := currentSaka % 19; temp { + case 0, 6, 11: + if currentSasih == Enum.Sasih.Destha.ID && !inSK { + if currentSaka != 1925 { + nampihCount++ + } + } + case 3, 8, 14, 16: + if currentSasih == Enum.Sasih.Sadha.ID && !inSK { + nampihCount++ + } + case 2, 10: + if currentSasih == Enum.Sasih.Destha.ID && inSK { + nampihCount++ + } + case 4: + if currentSasih == Enum.Sasih.Katiga.ID && inSK { + nampihCount++ + } + case 7: + if currentSasih == Enum.Sasih.Kasa.ID && inSK { + nampihCount++ + } + case 13: + if currentSasih == Enum.Sasih.Kadasa.ID && inSK { + nampihCount++ + } + case 15: + if currentSasih == Enum.Sasih.Karo.ID && inSK { + nampihCount++ + } + case 18: + if currentSasih == Enum.Sasih.Sadha.ID && inSK { + nampihCount++ + } + } + } + + res[0] = currentSaka + res[1] = currentSasih + + if dayTotal >= 0 { + if nampihCount == 2 { + res[2] = 1 + } else { + res[2] = 0 + } + } else { + if nampihCount == 1 { + res[2] = 1 + } else { + res[2] = 0 + } + } + + return res +} + +func getSasihDay(pivot PivotData, date carbon.Carbon) []int64 { + res := make([]int64, 3) + + pTime := pivot.Carbon + dayDiff := delta(pTime, date) + daySkip := int64(math.Ceil(float64(dayDiff) / float64(c_day_ngunaratri))) + dayTotal := pivot.SasihDay + dayDiff + daySkip + + res[0] = mod(int64(dayTotal), 30) + res[1] = 0 + if res[0] == 0 || res[0] > 15 { + res[1] = 1 + } + res[2] = 0 + if mod(dayDiff, c_day_ngunaratri) == 0 { + res[2] = 1 + } + res[0] = mod(res[0], 15) + if res[0] == 0 { + res[0] = 15 + } + + return res +} + +func getSasih(resSasih []int64) SasihData { + saka := resSasih[0] + sasih := resSasih[1] + res := newSasihSlice()[sasih] + + if resSasih[2] == 1 { + if res == Enum.Sasih.Destha { + if saka < 1914 { + res = Enum.Sasih.MalaDestha + } else { + res = Enum.Sasih.NampihDestha + } + } else if res == Enum.Sasih.Katiga { + res = Enum.Sasih.NampihKatiga + } else if res == Enum.Sasih.Kasa { + res = Enum.Sasih.NampihKasa + } else if res == Enum.Sasih.Kadasa { + res = Enum.Sasih.NampihKadasa + } else if res == Enum.Sasih.Karo { + res = Enum.Sasih.NampihKaro + } else if res == Enum.Sasih.Sadha { + if saka < 1914 { + res = Enum.Sasih.MalaSadha + } else { + res = Enum.Sasih.NampihSadha + } + } + } + + return res +} + +func getSasihDayInfo(resSasihDay []int64, sasih SasihData, saka int64) SasihDayInfoData { + date := resSasihDay[0] + isPangelong := resSasihDay[1] == 1 + isNgunaratri := resSasihDay[2] == 1 + + if isPangelong { + if date == 15 || (date == 14 && isNgunaratri) { + return Enum.SasihDayInfo.Tilem + } else if date == 14 && sasih == Enum.Sasih.Kapitu && saka == 1921 { + return Enum.SasihDayInfo.Tilem + } else { + return Enum.SasihDayInfo.Pangelong + } + } else { + if date == 15 || (date == 14 && isNgunaratri) { + return Enum.SasihDayInfo.Purnama + } else { + return Enum.SasihDayInfo.Penanggal + } + } +} + +func getPratithiSamutPada(sasihDay []int64, sasihDayInfo SasihDayInfoData, sasih SasihData, date carbon.Carbon) Data { + move := int64(0) + isNG := len(sasihDay) > 1 + day := sasihDay[0] + if isNG { + day = sasihDay[1] + } + + if sasihDayInfo.Reference() == Enum.SasihDayInfo.Penanggal { + if day == 1 && isNG { + move = 0 + } else { + if day == 1 && day <= 8 { + move = day - 1 + } else if day >= 9 && day <= 13 { + move = day - 2 + } else if day == 14 { + move = 11 + } else if day == 15 { + move = 0 + } + } + } else { + if day == 1 && isNG { + temp := date.AddDay() + nextDay := New(temp) + + if nextDay.Sasih.Reference() != sasih.Reference() { + move = -1 + } + } else { + if day >= 13 { + move = day - 11 + } else { + move = day - 1 + } + } + } + + start := newPratithiSamutPadaSlice()[sasih.Reference().ID] + newID := mod(start.ID-move, 12) + + return newPratithiSamutPadaSlice()[newID] +} diff --git a/watek_alit.go b/watek_alit.go new file mode 100644 index 0000000..eb21997 --- /dev/null +++ b/watek_alit.go @@ -0,0 +1,25 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type WatekAlit struct { + Lintah Data + Uler Data + Gajah Data + Lembu Data +} + +func newWatekAlit() WatekAlit { + return WatekAlit{ + Lintah: Data{0, "Lintah"}, + Uler: Data{1, "Uler"}, + Gajah: Data{2, "Gajah"}, + Lembu: Data{3, "Lembu"}, + } +} + +func newWatekAlitSlice() []Data { + data := newWatekAlit() + return []Data{data.Lintah, data.Uler, data.Gajah, data.Lembu} +} diff --git a/watek_madya.go b/watek_madya.go new file mode 100644 index 0000000..6a9d981 --- /dev/null +++ b/watek_madya.go @@ -0,0 +1,27 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type WatekMadya struct { + Wong Data + Gajah Data + Watu Data + Buta Data + Suku Data +} + +func newWatekMadya() WatekMadya { + return WatekMadya{ + Wong: Data{0, "Wong"}, + Gajah: Data{1, "Gajah"}, + Watu: Data{2, "Watu"}, + Buta: Data{3, "Buta"}, + Suku: Data{4, "Suku"}, + } +} + +func newWatekMadyaSlice() []Data { + data := newWatekMadya() + return []Data{data.Wong, data.Gajah, data.Watu, data.Buta, data.Suku} +} diff --git a/wuku.go b/wuku.go new file mode 100644 index 0000000..dbbb39d --- /dev/null +++ b/wuku.go @@ -0,0 +1,114 @@ +/* +Copyright © Portalnesia +*/ +package saka + +type WukuData struct { + ID int64 + Urip int64 + Name string +} + +type Wuku struct { + Sinta WukuData + Landep WukuData + Ukir WukuData + Kulantir WukuData + Tolu WukuData + Gumbreg WukuData + Wariga WukuData + Warigadean WukuData + Julungwangi WukuData + Sungsang WukuData + Dungulan WukuData + Kuningan WukuData + Langkir WukuData + Medangsia WukuData + Pujut WukuData + Pahang WukuData + Krulut WukuData + Merakih WukuData + Tambir WukuData + Medangkungan WukuData + Matal WukuData + Uye WukuData + Menail WukuData + Prangbakat WukuData + Bala WukuData + Ugu WukuData + Wayang WukuData + Klawu WukuData + Dukut WukuData + Watugunung WukuData +} + +func newWuku() Wuku { + return Wuku{ + Sinta: WukuData{0, 7, "Sinta"}, + Landep: WukuData{1, 1, "Landep"}, + Ukir: WukuData{2, 4, "Ukir"}, + Kulantir: WukuData{3, 6, "Kulantir"}, + Tolu: WukuData{4, 5, "Tolu"}, + Gumbreg: WukuData{5, 8, "Gumbreg"}, + Wariga: WukuData{6, 9, "Wariga"}, + Warigadean: WukuData{7, 3, "Warigadean"}, + Julungwangi: WukuData{8, 7, "Julungwangi"}, + Sungsang: WukuData{9, 1, "Sungsang"}, + Dungulan: WukuData{10, 4, "Dungulan"}, + Kuningan: WukuData{11, 6, "Kuningan"}, + Langkir: WukuData{12, 5, "Langkir"}, + Medangsia: WukuData{13, 8, "Medangsia"}, + Pujut: WukuData{14, 9, "Pujut"}, + Pahang: WukuData{15, 3, "Pahang"}, + Krulut: WukuData{16, 7, "Krulut"}, + Merakih: WukuData{17, 1, "Merakih"}, + Tambir: WukuData{18, 4, "Tambir"}, + Medangkungan: WukuData{19, 6, "Medangkungan"}, + Matal: WukuData{20, 5, "Matal"}, + Uye: WukuData{21, 8, "Uye"}, + Menail: WukuData{22, 9, "Menail"}, + Prangbakat: WukuData{23, 3, "Prangbakat"}, + Bala: WukuData{24, 7, "Bala"}, + Ugu: WukuData{25, 1, "Ugu"}, + Wayang: WukuData{26, 4, "Wayang"}, + Klawu: WukuData{27, 6, "Klawu"}, + Dukut: WukuData{28, 5, "Dukut"}, + Watugunung: WukuData{29, 8, "Watugunung"}, + } +} + +func newWukuSlice() []WukuData { + data := newWuku() + return []WukuData{ + data.Sinta, + data.Landep, + data.Ukir, + data.Kulantir, + data.Tolu, + data.Gumbreg, + data.Wariga, + data.Warigadean, + data.Julungwangi, + data.Sungsang, + data.Dungulan, + data.Kuningan, + data.Langkir, + data.Medangsia, + data.Pujut, + data.Pahang, + data.Krulut, + data.Merakih, + data.Tambir, + data.Medangkungan, + data.Matal, + data.Uye, + data.Menail, + data.Prangbakat, + data.Bala, + data.Ugu, + data.Wayang, + data.Klawu, + data.Dukut, + data.Watugunung, + } +}