From 9a04275029d4f8de3cf8e39b5feb1b7c4db9d80b Mon Sep 17 00:00:00 2001 From: Yinebeb Tariku <12098948-Yinebeb-01@users.noreply.gitlab.com> Date: Sat, 2 Mar 2024 10:20:13 +0000 Subject: [PATCH 1/2] Goc 6 bahire hasab --- README.md | 100 +++++++- cmd/main.go | 1 + docs/docs.go | 214 ++++++++++++++++++ docs/swagger.json | 214 ++++++++++++++++++ docs/swagger.yaml | 130 +++++++++++ internal/api/bahirehasab.go | 48 ++++ internal/api/date_converter.go | 26 ++- internal/module/bahirehasab/bahirehasab.go | 185 +++++++++++++++ .../module/bahirehasab/bahirehasab_test.go | 87 +++++++ internal/module/bahirehasab/const.go | 17 ++ internal/module/bahirehasab/model.go | 69 ++++++ internal/{ => module}/ethioGrego/ethiopian.go | 0 internal/{ => module}/ethioGrego/gregorian.go | 0 internal/{ => module}/ethioGrego/helper.go | 0 test/bahirehasab_test.go | 19 ++ test/ethioGrego_test.go | 6 +- 16 files changed, 1094 insertions(+), 22 deletions(-) create mode 100644 internal/api/bahirehasab.go create mode 100644 internal/module/bahirehasab/bahirehasab.go create mode 100644 internal/module/bahirehasab/bahirehasab_test.go create mode 100644 internal/module/bahirehasab/const.go create mode 100644 internal/module/bahirehasab/model.go rename internal/{ => module}/ethioGrego/ethiopian.go (100%) rename internal/{ => module}/ethioGrego/gregorian.go (100%) rename internal/{ => module}/ethioGrego/helper.go (100%) create mode 100644 test/bahirehasab_test.go diff --git a/README.md b/README.md index 018631b..573d799 100755 --- a/README.md +++ b/README.md @@ -1,21 +1,22 @@

logo

-

Ethiopian Date Converter

+

Ethiopian Calendar (ባሐረ-ሐሳብ)

## Description -The Ethiopian Date Converter API is designed to facilitate the conversion between Ethiopian dates -(in the format yy-mm-dd) and Gregorian dates. Ethiopia follows its own calendar system, which consists of 13 months, -each with 30 days. +The Ethiopian calendar(ባሕረ-ሀሳብ) is used to get Fasting and Holiday's specific date with in a year based on +[EOTC]()calendar. It also designed to facilitate the conversion between Ethiopian dates (in the format yy-mm-dd) and +Gregorian dates. Ethiopia follows its own calendar system, which consists of 13 months, each with 30 days. ### Functionality This API allows users to: +* Fetching all festivals with a year such as year, Basic data and Fasting dates. * Convert Ethiopian dates to Gregorian dates. * Convert Gregorian dates to Ethiopian dates. ### Usage -To utilize the API, simply send a date using the specified endpoints. The API will respond with the converted date -in JSON format. +To utilize the API, simply send a date or year using the specified endpoints. For the date conversion,the API will +respond with the converted date in JSON format whereas for the calendar, it will respond data in a json object. #### Example Usage @@ -64,13 +65,94 @@ Response: } ``` -## Installation +3. Get Ethiopian Calendar such as Holidays and Fasting dates. + +```curl +GET /bahire-hasab/{year} +``` + +* Parameters: + + `year:` The Ethiopian year. + +**Example**: + +```curl +GET /bahire-hasab/2016 +``` + +Response: + +```json +{ + "data": { + "year": { + "year":2016, + "evangelist_num":0, + "evangelist":"ዮሐንስ(John)", + "day_of_the_week":"ማክሰኞ(Tuesday)" + }, + "basic": { + "medeb":11, + "wenber":10, + "abektie":20, + "metiq":10, + "beale_metiq":2, + "mebaja_hamer":18, + "nenewie":{ + "DateOfTheMonth":18, + "MonthOfTheYear":6 + } + }, + "fasting":{ + "abiy":{ + "DateOfTheMonth":2, + "MonthOfTheYear":7 + }, + "debrezeit":{ + "DateOfTheMonth":29, + "MonthOfTheYear":7 + }, + "hosanna":{ + "DateOfTheMonth":20, + "MonthOfTheYear":8 + }, + "siklet":{ + "DateOfTheMonth":25, + "MonthOfTheYear":8 + }, + "tinsaye":{ + "DateOfTheMonth":27, + "MonthOfTheYear":8 + }, + "rkbekahnat":{ + "DateOfTheMonth":21, + "MonthOfTheYear":9 + }, + "dihnet":{ + "DateOfTheMonth":19, + "MonthOfTheYear":10 + },"hawariyat":{ + "DateOfTheMonth":17, + "MonthOfTheYear":10 + }, + "erget":{ + "DateOfTheMonth":6, + "MonthOfTheYear":10}, + "peraklitos":{ + "DateOfTheMonth":16, + "MonthOfTheYear":10 + } + } + } +} +``` +## Installation Install using below go command: ```bash go get gitlab.com/Yinebeb-01/ethiopiandateconverter ``` ## Author -- [Yinebeb T.](https://github.com/Yinebeb-01/) -- [python version](https://github.com/dimagi/ethiopian-date-converter) \ No newline at end of file +- [Yinebeb T.](https://github.com/Yinebeb-01/) \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 6ca78b3..840c311 100755 --- a/cmd/main.go +++ b/cmd/main.go @@ -40,6 +40,7 @@ func main() { v1.GET("", api2.HomePage) v1.GET("/et-to-ad/:date", api2.Gregorian) v1.GET("/ad-to-et/:date", api2.Ethiopian) + v1.GET("/bahire-hasab/:year", api2.BahireHasab) router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) } diff --git a/docs/docs.go b/docs/docs.go index 8c7353d..9785358 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -101,6 +101,50 @@ const docTemplate = `{ } } }, + "/bahire-hasab/{year}": { + "get": { + "description": "Get years fasting and festival date", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Bahirehasab" + ], + "summary": "Bahirehasab (ባህረ-ሐሳብ)", + "parameters": [ + { + "type": "string", + "description": "year", + "name": "year", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bahirehasab.Festival" + } + }, + "400": { + "description": "Bad Request", + "schema": {} + }, + "404": { + "description": "Not Found", + "schema": {} + }, + "500": { + "description": "Internal Server Error", + "schema": {} + } + } + } + }, "/et-to-ad/{date}": { "get": { "description": "Get gregorian date string from ethiopian date", @@ -146,6 +190,176 @@ const docTemplate = `{ } } }, + "definitions": { + "bahirehasab.Basic": { + "type": "object", + "properties": { + "abektie": { + "description": "Abekti (አበቅቴ)", + "type": "integer" + }, + "beale_metiq": { + "description": "BealeMetiq (በዓለ-መጥቅ), 1 =መስከረም፣ 2 = ጥቅምት", + "type": "integer" + }, + "mebaja_hamer": { + "description": "MebajaHamer (መባጃ ሃመር)", + "type": "integer" + }, + "medeb": { + "description": "Medeb (መደብ)", + "type": "integer" + }, + "metiq": { + "description": "Metiq (መጥቅ)", + "type": "integer" + }, + "nenewie": { + "description": "Nenewie የነነዌ ፆም የሚውልበት ቀን", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "wenber": { + "description": "Wenber (ወንበር)", + "type": "integer" + } + } + }, + "bahirehasab.Date": { + "type": "object", + "properties": { + "dateOfTheMonth": { + "type": "integer" + }, + "monthOfTheYear": { + "type": "integer" + } + } + }, + "bahirehasab.Fasting": { + "type": "object", + "properties": { + "abiy": { + "description": "Abiy tsome (አብይ ፆም)", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "debrezeit": { + "description": "DebreZeit ደብረ ዘይት", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "dihnet": { + "description": "Dihnet (ፆመ ድህነት), Wednesday and Friday Weekly fast", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "erget": { + "description": "Erget (እርገት)፣ Ascension", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "hawariyat": { + "description": "Hawariyat ( ፆመ ሐዋሪያት), fast of the Holy Apostles", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "hosanna": { + "description": "Hosanna ሆሳህና", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "peraklitos": { + "description": "Peraklitos (ጰራቅሊጦስ)፣ Paraclete", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "rkbekahnat": { + "description": "RkbeKahnat (ርክበ ካህናት)", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "siklet": { + "description": "Siklet (ስቅለት), Good Friday", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "tinsaye": { + "description": "Tinsaye (ፋሲካ), resurrection", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + } + } + }, + "bahirehasab.Festival": { + "type": "object", + "properties": { + "basic": { + "$ref": "#/definitions/bahirehasab.Basic" + }, + "fasting": { + "$ref": "#/definitions/bahirehasab.Fasting" + }, + "year": { + "$ref": "#/definitions/bahirehasab.Year" + } + } + }, + "bahirehasab.Year": { + "type": "object", + "properties": { + "day_of_the_week": { + "description": "DayOfTheWeek the day in which new year fall", + "type": "string" + }, + "evangelist": { + "description": "Evangelist ወንጌላዊው in name", + "type": "string" + }, + "evangelist_num": { + "description": "EvangelistNum (Evangelist) ወንጌላዊው in number", + "type": "integer" + }, + "year": { + "description": "Year in Ethiopian calendar", + "type": "integer" + } + } + } + }, "securityDefinitions": { "BasicAuth": { "type": "basic" diff --git a/docs/swagger.json b/docs/swagger.json index b3e7455..074a7e2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -95,6 +95,50 @@ } } }, + "/bahire-hasab/{year}": { + "get": { + "description": "Get years fasting and festival date", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Bahirehasab" + ], + "summary": "Bahirehasab (ባህረ-ሐሳብ)", + "parameters": [ + { + "type": "string", + "description": "year", + "name": "year", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bahirehasab.Festival" + } + }, + "400": { + "description": "Bad Request", + "schema": {} + }, + "404": { + "description": "Not Found", + "schema": {} + }, + "500": { + "description": "Internal Server Error", + "schema": {} + } + } + } + }, "/et-to-ad/{date}": { "get": { "description": "Get gregorian date string from ethiopian date", @@ -140,6 +184,176 @@ } } }, + "definitions": { + "bahirehasab.Basic": { + "type": "object", + "properties": { + "abektie": { + "description": "Abekti (አበቅቴ)", + "type": "integer" + }, + "beale_metiq": { + "description": "BealeMetiq (በዓለ-መጥቅ), 1 =መስከረም፣ 2 = ጥቅምት", + "type": "integer" + }, + "mebaja_hamer": { + "description": "MebajaHamer (መባጃ ሃመር)", + "type": "integer" + }, + "medeb": { + "description": "Medeb (መደብ)", + "type": "integer" + }, + "metiq": { + "description": "Metiq (መጥቅ)", + "type": "integer" + }, + "nenewie": { + "description": "Nenewie የነነዌ ፆም የሚውልበት ቀን", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "wenber": { + "description": "Wenber (ወንበር)", + "type": "integer" + } + } + }, + "bahirehasab.Date": { + "type": "object", + "properties": { + "dateOfTheMonth": { + "type": "integer" + }, + "monthOfTheYear": { + "type": "integer" + } + } + }, + "bahirehasab.Fasting": { + "type": "object", + "properties": { + "abiy": { + "description": "Abiy tsome (አብይ ፆም)", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "debrezeit": { + "description": "DebreZeit ደብረ ዘይት", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "dihnet": { + "description": "Dihnet (ፆመ ድህነት), Wednesday and Friday Weekly fast", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "erget": { + "description": "Erget (እርገት)፣ Ascension", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "hawariyat": { + "description": "Hawariyat ( ፆመ ሐዋሪያት), fast of the Holy Apostles", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "hosanna": { + "description": "Hosanna ሆሳህና", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "peraklitos": { + "description": "Peraklitos (ጰራቅሊጦስ)፣ Paraclete", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "rkbekahnat": { + "description": "RkbeKahnat (ርክበ ካህናት)", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "siklet": { + "description": "Siklet (ስቅለት), Good Friday", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + }, + "tinsaye": { + "description": "Tinsaye (ፋሲካ), resurrection", + "allOf": [ + { + "$ref": "#/definitions/bahirehasab.Date" + } + ] + } + } + }, + "bahirehasab.Festival": { + "type": "object", + "properties": { + "basic": { + "$ref": "#/definitions/bahirehasab.Basic" + }, + "fasting": { + "$ref": "#/definitions/bahirehasab.Fasting" + }, + "year": { + "$ref": "#/definitions/bahirehasab.Year" + } + } + }, + "bahirehasab.Year": { + "type": "object", + "properties": { + "day_of_the_week": { + "description": "DayOfTheWeek the day in which new year fall", + "type": "string" + }, + "evangelist": { + "description": "Evangelist ወንጌላዊው in name", + "type": "string" + }, + "evangelist_num": { + "description": "EvangelistNum (Evangelist) ወንጌላዊው in number", + "type": "integer" + }, + "year": { + "description": "Year in Ethiopian calendar", + "type": "integer" + } + } + } + }, "securityDefinitions": { "BasicAuth": { "type": "basic" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6384b66..1f44d73 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,4 +1,104 @@ basePath: /v1 +definitions: + bahirehasab.Basic: + properties: + abektie: + description: Abekti (አበቅቴ) + type: integer + beale_metiq: + description: BealeMetiq (በዓለ-መጥቅ), 1 =መስከረም፣ 2 = ጥቅምት + type: integer + mebaja_hamer: + description: MebajaHamer (መባጃ ሃመር) + type: integer + medeb: + description: Medeb (መደብ) + type: integer + metiq: + description: Metiq (መጥቅ) + type: integer + nenewie: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Nenewie የነነዌ ፆም የሚውልበት ቀን + wenber: + description: Wenber (ወንበር) + type: integer + type: object + bahirehasab.Date: + properties: + dateOfTheMonth: + type: integer + monthOfTheYear: + type: integer + type: object + bahirehasab.Fasting: + properties: + abiy: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Abiy tsome (አብይ ፆም) + debrezeit: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: DebreZeit ደብረ ዘይት + dihnet: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Dihnet (ፆመ ድህነት), Wednesday and Friday Weekly fast + erget: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Erget (እርገት)፣ Ascension + hawariyat: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Hawariyat ( ፆመ ሐዋሪያት), fast of the Holy Apostles + hosanna: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Hosanna ሆሳህና + peraklitos: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Peraklitos (ጰራቅሊጦስ)፣ Paraclete + rkbekahnat: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: RkbeKahnat (ርክበ ካህናት) + siklet: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Siklet (ስቅለት), Good Friday + tinsaye: + allOf: + - $ref: '#/definitions/bahirehasab.Date' + description: Tinsaye (ፋሲካ), resurrection + type: object + bahirehasab.Festival: + properties: + basic: + $ref: '#/definitions/bahirehasab.Basic' + fasting: + $ref: '#/definitions/bahirehasab.Fasting' + year: + $ref: '#/definitions/bahirehasab.Year' + type: object + bahirehasab.Year: + properties: + day_of_the_week: + description: DayOfTheWeek the day in which new year fall + type: string + evangelist: + description: Evangelist ወንጌላዊው in name + type: string + evangelist_num: + description: EvangelistNum (Evangelist) ወንጌላዊው in number + type: integer + year: + description: Year in Ethiopian calendar + type: integer + type: object host: calendar.st-son.com info: contact: @@ -66,6 +166,36 @@ paths: summary: Gregorian to Ethiopian tags: - Date-Conversion + /bahire-hasab/{year}: + get: + consumes: + - application/json + description: Get years fasting and festival date + parameters: + - description: year + in: path + name: year + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/bahirehasab.Festival' + "400": + description: Bad Request + schema: {} + "404": + description: Not Found + schema: {} + "500": + description: Internal Server Error + schema: {} + summary: Bahirehasab (ባህረ-ሐሳብ) + tags: + - Bahirehasab /et-to-ad/{date}: get: consumes: diff --git a/internal/api/bahirehasab.go b/internal/api/bahirehasab.go new file mode 100644 index 0000000..1fa553f --- /dev/null +++ b/internal/api/bahirehasab.go @@ -0,0 +1,48 @@ +package api + +import ( + "github.com/gin-gonic/gin" + "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/bahirehasab" + "net/http" + "strconv" +) + +// BahireHasab +// @Summary Bahirehasab (ባህረ-ሐሳብ) +// @Description Get years fasting and festival date +// @Tags Bahirehasab +// @Accept json +// @Produce json +// @Param year path string true "year" +// @Success 200 {object} bahirehasab.Festival +// @Failure 400 {object} error +// @Failure 404 {object} error +// @Failure 500 {object} error +// @Router /bahire-hasab/{year} [get] +func BahireHasab(ctx *gin.Context) { + yearString, state := ctx.Params.Get("year") + if !state { + ctx.JSON(http.StatusBadRequest, gin.H{ + "message": "Empty year value", + }) + return + } + year, err := strconv.Atoi(yearString) + if err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{ + "message": "not a valid year", + }) + return + } + + festival, err := bahirehasab.BahireHasab(year) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + ctx.JSON(http.StatusOK, gin.H{ + "data": festival, + }) +} diff --git a/internal/api/date_converter.go b/internal/api/date_converter.go index 2a62cef..e2842d5 100644 --- a/internal/api/date_converter.go +++ b/internal/api/date_converter.go @@ -2,12 +2,12 @@ package api import ( "errors" + "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/ethioGrego" "net/http" "strconv" "strings" "github.com/gin-gonic/gin" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/ethioGrego" ) // Ethiopian : Gregorian to Ethiopian date converter @@ -24,13 +24,16 @@ import ( // @Router /ad-to-et/{date} [get] func Ethiopian(ctx *gin.Context) { dateString, state := ctx.Params.Get("date") - if state { - dateString = strings.TrimPrefix(dateString, "date=") + if !state { + ctx.JSON(http.StatusBadRequest, gin.H{ + "message": "empty date", + }) + return } var date = strings.Split(dateString, "-") if len(date) > 3 { ctx.JSON(http.StatusBadRequest, gin.H{ - "response": "not a valid date", + "message": "not a valid date", }) return } @@ -41,7 +44,7 @@ func Ethiopian(ctx *gin.Context) { EtDate, err := ethioGrego.Ethiopian(year, month, day) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ - "response": err.Error(), + "error": err.Error(), }) return } @@ -64,13 +67,16 @@ func Ethiopian(ctx *gin.Context) { // @Router /et-to-ad/{date} [get] func Gregorian(ctx *gin.Context) { dateString, state := ctx.Params.Get("date") - if state { - dateString = strings.TrimPrefix(dateString, "date=") + if !state { + ctx.JSON(http.StatusBadRequest, gin.H{ + "message": "empty date", + }) + return } var date = strings.Split(dateString, "-") if len(date) > 3 { ctx.JSON(http.StatusBadRequest, gin.H{ - "response": "not a valid date", + "message": "not a valid date", }) return } @@ -83,11 +89,11 @@ func Gregorian(ctx *gin.Context) { if err != nil { if err.Error() == "not a valid date" { ctx.JSON(http.StatusBadRequest, gin.H{ - "response": err.Error(), + "error": err.Error(), }) } else { ctx.JSON(http.StatusInternalServerError, gin.H{ - "response": errors.New("internal server error"), + "error": errors.New("internal server error"), }) } return diff --git a/internal/module/bahirehasab/bahirehasab.go b/internal/module/bahirehasab/bahirehasab.go new file mode 100644 index 0000000..4cde20a --- /dev/null +++ b/internal/module/bahirehasab/bahirehasab.go @@ -0,0 +1,185 @@ +package bahirehasab + +import ( + "fmt" + "log" +) + +// የበዓላትና የአጽዋማት ተውሳክ +var tewsak = map[string]int{ + "abiy": 14, + "debrezeit": 41, + "hosahna": 62, + "siklet": 67, + "tinsaye": 69, + "rkbekahnat": 93, + "erget": 108, + "peraklitos": 118, + "hawariyat": 119, + "dihnet": 121, +} + +func BahireHasab(etYear int) (Festival, error) { + if etYear < 0 { + return Festival{}, fmt.Errorf("invalid Ethiopian Year %v", etYear) + } + year := getYear(etYear) + basic := getBasic(etYear) + fasting := getFasting(etYear) + return Festival{ + Year: year, + Basic: basic, + Fasting: fasting, + }, nil +} + +func getYear(year int) Year { + var wngName string + ameteAlem := year + 5500 + wngNum := ameteAlem % 4 + switch wngNum { + case 0: + wngName = "ዮሐንስ(John)" + break + case 1: + wngName = "ማቲዎስ(Matthew)" + break + case 2: + wngName = "ማርቆስ(Mark)" + break + case 3: + wngName = "ሉቃስ(Luke)" + } + meteneRabit := (ameteAlem - wngNum) / 4 + tinteQemer := (ameteAlem + meteneRabit) % 7 + + return Year{ + Year: year, + EvangelistNum: wngNum, + Evangelist: wngName, + DayOfTheWeek: getDayOfTheWeek(tinteQemer), + } +} + +func getDayOfTheWeek(day int) string { + switch day { + case 0: + return "ሰኞ(Monday)" + case 1: + return "ማክሰኞ(Tuesday)" + case 2: + return "እሮብ(Wednesday)" + case 3: + return "ሃሙስ(Thursday)" + case 4: + return "አርብ(Friday)" + case 5: + return "ቅዳሜ(Saturday)" + case 6: + return "እሁድ(Sunday)" + default: + return "invalid day" + } +} + +func getBasic(year int) Basic { + wenber := 0 + amtAlem := year + 5500 + medeb := amtAlem % 19 + if medeb == 0 { + wenber = 18 + } else { + wenber = medeb - 1 + } + + abektie := (wenber * TinteAbektie) % 30 + metiq := (wenber * TinteMetiq) % 30 + wngNum := amtAlem % 4 + meteneRabit := (amtAlem - wngNum) / 4 + tinteQemer := (amtAlem + meteneRabit) % 7 + + var dayOfWeekForMtqNum int + bealeMetq := 0 + if metiq > 14 { + bealeMetq = 1 + dayOfWeekForMtqNum = (metiq-1)%7 + tinteQemer + log.Printf("የዓመቱ መጥቅ የሚውለው መስከረም %v %v ነው", metiq, getDayOfTheWeek(dayOfWeekForMtqNum)) + } else if metiq < 14 { + bealeMetq = 2 + dayOfWeekForMtqNum = (metiq+29)%7 + tinteQemer + log.Printf("የዓመቱ መጥቅ የሚውለው ጥቅምት %v %v ነው", metiq, getDayOfTheWeek(dayOfWeekForMtqNum)) + } + + twsakOfDay := 0 + switch dayOfWeekForMtqNum { + case 0: + twsakOfDay = monday + case 1: + twsakOfDay = tuesday + case 2: + twsakOfDay = wednesday + case 3: + twsakOfDay = thursday + case 4: + twsakOfDay = friday + case 5: + twsakOfDay = saturday + case 6: + twsakOfDay = sunday + } + + mebajaHamer := metiq + twsakOfDay // የነነዌ ፆም የሚውልበት ቀን + nenewie := Date{} + if bealeMetq == 1 && mebajaHamer <= 30 { + log.Printf("ፆመ ነነዌ የሚውለው ጥር %v ነው", mebajaHamer) + nenewie = Date{ + DateOfTheMonth: mebajaHamer, + MonthOfTheYear: 5, + } + } else if bealeMetq == 2 || (bealeMetq == 1 && mebajaHamer > 30) { + log.Printf("ፆመ ነነዌ የሚውለው የካቲት %v ነው", mebajaHamer%30) + nenewie = Date{ + DateOfTheMonth: mebajaHamer, + MonthOfTheYear: 6, + } + } + + return Basic{ + Medeb: medeb, + Wenber: wenber, + Abektie: abektie, + Metiq: metiq, + BealeMetiq: bealeMetq, + MebajaHamer: mebajaHamer, + Nenewie: nenewie, + } +} + +func getFasting(etYear int) Fasting { + basic := getBasic(etYear) + fastingMap := map[string]Date{} + for name, val := range tewsak { + daySum, offset := 0, 0 + daySum = basic.Nenewie.DateOfTheMonth + val + offset = (daySum - (daySum % 30)) / 30 + date := Date{ + DateOfTheMonth: daySum % 30, + MonthOfTheYear: basic.Nenewie.MonthOfTheYear + offset, + } + fastingMap[name] = date + } + + fasting := Fasting{} + fasting.Abiy = fastingMap["abiy"] + fasting.DebreZeit = fastingMap["debrezeit"] + fasting.Hosanna = fastingMap["hosahna"] + fasting.Siklet = fastingMap["siklet"] + fasting.Tinsaye = fastingMap["tinsaye"] + fasting.RkbeKahnat = fastingMap["rkbekahnat"] + fasting.Erget = fastingMap["erget"] + fasting.Peraklitos = fastingMap["peraklitos"] + fasting.Hawariyat = fastingMap["hawariyat"] + fasting.Dihnet = fastingMap["dihnet"] + + return fasting +} diff --git a/internal/module/bahirehasab/bahirehasab_test.go b/internal/module/bahirehasab/bahirehasab_test.go new file mode 100644 index 0000000..b7ccbf3 --- /dev/null +++ b/internal/module/bahirehasab/bahirehasab_test.go @@ -0,0 +1,87 @@ +package bahirehasab + +import "testing" + +func TestGetYear(t *testing.T) { + sampleYear := Year{ + Year: 2016, + EvangelistNum: 0, + Evangelist: "ዮሐንስ(John)", + DayOfTheWeek: "ማክሰኞ(Tuesday)", + } + year := getYear(sampleYear.Year) + if year != sampleYear { + t.Errorf("Test failed, expected %v got %v", sampleYear, year) + } +} + +func TestBasic(t *testing.T) { + // Basic for the year 2016 + expected := Basic{ + Medeb: 11, + Wenber: 10, + Abektie: 20, + Metiq: 10, + BealeMetiq: 2, + MebajaHamer: 18, + Nenewie: Date{ + DateOfTheMonth: 18, + MonthOfTheYear: 6, + }, + } + got := getBasic(2016) + if got != expected { + t.Errorf("Test failed: expected %v got %v", expected, got) + } +} + +func TestFasting(t *testing.T) { + // year 2016 sample fasting dates + expected := Fasting{ + Abiy: Date{ + DateOfTheMonth: 2, + MonthOfTheYear: 7, + }, + DebreZeit: Date{ + DateOfTheMonth: 29, + MonthOfTheYear: 7, + }, + Hosanna: Date{ + DateOfTheMonth: 20, + MonthOfTheYear: 8, + }, + Siklet: Date{ + DateOfTheMonth: 25, + MonthOfTheYear: 8, + }, + Tinsaye: Date{ + DateOfTheMonth: 27, + MonthOfTheYear: 8, + }, + RkbeKahnat: Date{ + DateOfTheMonth: 21, + MonthOfTheYear: 9, + }, + Erget: Date{ + DateOfTheMonth: 6, + MonthOfTheYear: 10, + }, + Peraklitos: Date{ + DateOfTheMonth: 16, + MonthOfTheYear: 10, + }, + Hawariyat: Date{ + DateOfTheMonth: 17, + MonthOfTheYear: 10, + }, + Dihnet: Date{ + DateOfTheMonth: 19, + MonthOfTheYear: 10, + }, + } + + got := getFasting(2016) + if expected != got { + t.Errorf("Test failed expected %v got %v", expected, got) + } +} diff --git a/internal/module/bahirehasab/const.go b/internal/module/bahirehasab/const.go new file mode 100644 index 0000000..09d0751 --- /dev/null +++ b/internal/module/bahirehasab/const.go @@ -0,0 +1,17 @@ +package bahirehasab + +const ( + TinteMetiq = 19 + TinteAbektie = 11 +) + +// የዕለታት ተውሳክ +const ( + saturday = 8 + sunday = 7 + monday = 6 + tuesday = 5 + wednesday = 4 + thursday = 3 + friday = 2 +) diff --git a/internal/module/bahirehasab/model.go b/internal/module/bahirehasab/model.go new file mode 100644 index 0000000..95d1ef0 --- /dev/null +++ b/internal/module/bahirehasab/model.go @@ -0,0 +1,69 @@ +package bahirehasab + +// Festival contains all relevant information on ባሐረ-ሃሳብ calendar such as Year, Basic events and Fasting dates. +type Festival struct { + Year Year `json:"year"` + Basic Basic `json:"basic"` + Fasting Fasting `json:"fasting"` +} + +// Basic contains bahirehasab related values such as መጥቅ including ነነዌ ፆም which is used to get all others. +type Basic struct { + //Medeb (መደብ) + Medeb int `json:"medeb"` + //Wenber (ወንበር) + Wenber int `json:"wenber"` + // Abekti (አበቅቴ) + Abektie int `json:"abektie"` + // Metiq (መጥቅ) + Metiq int `json:"metiq"` + // BealeMetiq (በዓለ-መጥቅ), 1 =መስከረም፣ 2 = ጥቅምት + BealeMetiq int `json:"beale_metiq"` + // MebajaHamer (መባጃ ሃመር) + MebajaHamer int `json:"mebaja_hamer"` + // Nenewie የነነዌ ፆም የሚውልበት ቀን + Nenewie Date `json:"nenewie"` +} + +// Year contains New year data such as Evangelist. +type Year struct { + // Year in Ethiopian calendar + Year int `json:"year"` + // EvangelistNum (Evangelist) ወንጌላዊው in number + EvangelistNum int `json:"evangelist_num"` + // Evangelist ወንጌላዊው in name + Evangelist string `json:"evangelist"` + // DayOfTheWeek the day in which new year fall + DayOfTheWeek string `json:"day_of_the_week"` +} + +// Date contains date of the month and month of the year. +// መስከረም = 0, DateOfTheMonth goes 1 to 30 +type Date struct { + DateOfTheMonth int + MonthOfTheYear int +} + +// Fasting አጽዋማትና በዓላት +type Fasting struct { + // Abiy tsome (አብይ ፆም) + Abiy Date `json:"abiy"` + // DebreZeit ደብረ ዘይት + DebreZeit Date `json:"debrezeit"` + // Hosanna ሆሳህና + Hosanna Date `json:"hosanna"` + // Siklet (ስቅለት), Good Friday + Siklet Date `json:"siklet"` + // Tinsaye (ፋሲካ), resurrection + Tinsaye Date `json:"tinsaye"` + // RkbeKahnat (ርክበ ካህናት) + RkbeKahnat Date `json:"rkbekahnat"` + // Dihnet (ፆመ ድህነት), Wednesday and Friday Weekly fast + Dihnet Date `json:"dihnet"` + // Hawariyat ( ፆመ ሐዋሪያት), fast of the Holy Apostles + Hawariyat Date `json:"hawariyat"` + // Erget (እርገት)፣ Ascension + Erget Date `json:"erget"` + // Peraklitos (ጰራቅሊጦስ)፣ Paraclete + Peraklitos Date `json:"peraklitos"` +} diff --git a/internal/ethioGrego/ethiopian.go b/internal/module/ethioGrego/ethiopian.go similarity index 100% rename from internal/ethioGrego/ethiopian.go rename to internal/module/ethioGrego/ethiopian.go diff --git a/internal/ethioGrego/gregorian.go b/internal/module/ethioGrego/gregorian.go similarity index 100% rename from internal/ethioGrego/gregorian.go rename to internal/module/ethioGrego/gregorian.go diff --git a/internal/ethioGrego/helper.go b/internal/module/ethioGrego/helper.go similarity index 100% rename from internal/ethioGrego/helper.go rename to internal/module/ethioGrego/helper.go diff --git a/test/bahirehasab_test.go b/test/bahirehasab_test.go new file mode 100644 index 0000000..4d67b1c --- /dev/null +++ b/test/bahirehasab_test.go @@ -0,0 +1,19 @@ +package test + +import ( + "fmt" + "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/bahirehasab" + "testing" +) + +func TestBahireHasab(t *testing.T) { + res, err := bahirehasab.BahireHasab(2016) + fmt.Print(res, err) + if res.Year.Year != 2016 { + t.Errorf("Test faled, expected %v but got %v ", 2016, res.Year.Year) + } + + if err != nil { + t.Errorf("Test faled, expected %v but got %v ", nil, err) + } +} diff --git a/test/ethioGrego_test.go b/test/ethioGrego_test.go index e5e5043..0c73120 100755 --- a/test/ethioGrego_test.go +++ b/test/ethioGrego_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "github.com/spf13/viper" + "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/ethioGrego" "io/ioutil" "net/http" "reflect" @@ -11,7 +12,6 @@ import ( "testing" "github.com/cucumber/godog" - ethioGrego2 "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/ethioGrego" ) var res *http.Response @@ -27,11 +27,11 @@ func TestEthiopianDate(t *testing.T) { ethiopianDate := "2015-01-18 00:00:00 +0000 UTC" gregorianDate := "2022-09-28 00:00:00 +0000 UTC" - time, err := ethioGrego2.Ethiopian(2022, 9, 28) + time, err := ethioGrego.Ethiopian(2022, 9, 28) if err == nil { expectedEthio = time.String() } - time, err = ethioGrego2.Gregorian(2015, 1, 18) + time, err = ethioGrego.Gregorian(2015, 1, 18) if err == nil { expectedGrego = time.String() } From e5209b0ba9eb13fb39487c57de9324009d2d90d8 Mon Sep 17 00:00:00 2001 From: Yinebeb-01 Date: Sat, 2 Mar 2024 14:56:48 +0300 Subject: [PATCH 2/2] typo error fixed --- README.md | 7 ++++--- cmd/main.go | 6 +++--- go.mod | 2 +- internal/api/bahirehasab.go | 2 +- internal/api/date_converter.go | 2 +- test/bahirehasab_test.go | 2 +- test/ethioGrego_test.go | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 573d799..5d2d894 100755 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@

logo

-

Ethiopian Calendar (ባሐረ-ሐሳብ)

+

Ethiopian Calendar (ባሕረ-ሐሳብ)

## Description The Ethiopian calendar(ባሕረ-ሀሳብ) is used to get Fasting and Holiday's specific date with in a year based on -[EOTC]()calendar. It also designed to facilitate the conversion between Ethiopian dates (in the format yy-mm-dd) and +[EOTC](https://www.ethiopianorthodox.org/) calendar. It also designed to facilitate the conversion between Ethiopian dates (in the format yy-mm-dd) and Gregorian dates. Ethiopia follows its own calendar system, which consists of 13 months, each with 30 days. ### Functionality @@ -132,7 +132,8 @@ Response: "dihnet":{ "DateOfTheMonth":19, "MonthOfTheYear":10 - },"hawariyat":{ + }, + "hawariyat":{ "DateOfTheMonth":17, "MonthOfTheYear":10 }, diff --git a/cmd/main.go b/cmd/main.go index 840c311..edd4477 100755 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,9 +9,9 @@ import ( "github.com/spf13/viper" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/config" - docs "gitlab.com/Yinebeb-01/ethiopiandateconverter/docs" - api2 "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/api" + "gitlab.com/Yinebeb-01/ethiopiancalendar/config" + docs "gitlab.com/Yinebeb-01/ethiopiancalendar/docs" + api2 "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/api" ) // @title EthioGrego diff --git a/go.mod b/go.mod index 6f5a924..15f098e 100755 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gitlab.com/Yinebeb-01/ethiopiandateconverter +module gitlab.com/Yinebeb-01/ethiopiancalendar go 1.19 diff --git a/internal/api/bahirehasab.go b/internal/api/bahirehasab.go index 1fa553f..af04c42 100644 --- a/internal/api/bahirehasab.go +++ b/internal/api/bahirehasab.go @@ -2,7 +2,7 @@ package api import ( "github.com/gin-gonic/gin" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/bahirehasab" + "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/bahirehasab" "net/http" "strconv" ) diff --git a/internal/api/date_converter.go b/internal/api/date_converter.go index e2842d5..8d395fe 100644 --- a/internal/api/date_converter.go +++ b/internal/api/date_converter.go @@ -2,7 +2,7 @@ package api import ( "errors" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/ethioGrego" + "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/ethioGrego" "net/http" "strconv" "strings" diff --git a/test/bahirehasab_test.go b/test/bahirehasab_test.go index 4d67b1c..e44e9c5 100644 --- a/test/bahirehasab_test.go +++ b/test/bahirehasab_test.go @@ -2,7 +2,7 @@ package test import ( "fmt" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/bahirehasab" + "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/bahirehasab" "testing" ) diff --git a/test/ethioGrego_test.go b/test/ethioGrego_test.go index 0c73120..524b6ba 100755 --- a/test/ethioGrego_test.go +++ b/test/ethioGrego_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "github.com/spf13/viper" - "gitlab.com/Yinebeb-01/ethiopiandateconverter/internal/module/ethioGrego" + "gitlab.com/Yinebeb-01/ethiopiancalendar/internal/module/ethioGrego" "io/ioutil" "net/http" "reflect"