Browse Source

initial Era logic

joeybloggs 9 years ago
parent
commit
60c6c16eec
3 changed files with 38 additions and 0 deletions
  1. 9 0
      calendar.go
  2. 19 0
      cmd/resources/generate_resources.go
  3. 10 0
      locale.go

+ 9 - 0
calendar.go

@@ -7,6 +7,15 @@ import (
 	"time"
 )
 
+// // Era denotes the Era types
+// type Era uint8
+
+// // Era types
+// const (
+// 	AD Era = iota
+// 	BC
+// )
+
 const (
 	am = "am"
 	pm = "pm"

+ 19 - 0
cmd/resources/generate_resources.go

@@ -197,13 +197,16 @@ func main() {
 		locs[loc] = strings.ToLower(strings.Replace(loc, "_", "", -1))
 
 		if ldml.Dates != nil && ldml.Dates.Calendars != nil {
+
 			var calendar i18n.Calendar
 			ldmlCar := ldml.Dates.Calendars.Calendar[0]
+
 			for _, cal := range ldml.Dates.Calendars.Calendar {
 				if cal.Type == "gregorian" {
 					ldmlCar = cal
 				}
 			}
+
 			if ldmlCar.DateFormats != nil {
 				for _, datefmt := range ldmlCar.DateFormats.DateFormatLength {
 					switch datefmt.Type {
@@ -370,6 +373,22 @@ func main() {
 				// 	calendar.FormatNames.Periods.Abbreviated = calendar.FormatNames.Periods.Wide
 				// }
 			}
+
+			if ldmlCar.Eras != nil {
+
+				var eras i18n.Eras
+
+				eras.BC.Full = ldmlCar.Eras.EraNames.Era[0].Data()
+				eras.BC.Abbrev = ldmlCar.Eras.EraAbbr.Era[0].Data()
+				eras.BC.Narrow = ldmlCar.Eras.EraNarrow.Era[0].Data()
+
+				eras.AD.Full = ldmlCar.Eras.EraNames.Era[1].Data()
+				eras.AD.Abbrev = ldmlCar.Eras.EraAbbr.Era[1].Data()
+				eras.AD.Narrow = ldmlCar.Eras.EraNarrow.Era[1].Data()
+
+				calendar.FormatNames.Eras = eras
+			}
+
 			calendars[loc] = calendar
 		}
 	}

+ 10 - 0
locale.go

@@ -66,8 +66,18 @@ type CalendarFormatNames struct {
 	Months  CalendarMonthFormatNames
 	Days    CalendarDayFormatNames
 	Periods CalendarPeriodFormatNames
+	Eras    Eras
 }
 
+// Eras contains the Era information for both AD and BC
+type Eras struct {
+	AD CalendarEraFormatNames
+	BC CalendarEraFormatNames
+}
+
+// CalendarEraFormatNames contains the Era name information
+type CalendarEraFormatNames struct{ Full, Abbrev, Narrow string }
+
 // CalendarMonthFormatNames contains the DateTime month formats information
 type CalendarMonthFormatNames struct {
 	Abbreviated CalendarMonthFormatNameValue