no longer expand the dates for *any

This commit is contained in:
Radu Ioan Fericean
2013-08-02 19:33:47 +03:00
parent 8c8f003239
commit 13e8f53230
5 changed files with 24 additions and 67 deletions

View File

@@ -20,7 +20,6 @@ package engine
import (
"fmt"
"reflect"
"sort"
"strconv"
"strings"
@@ -88,9 +87,6 @@ func (ys Years) Serialize(sep string) string {
return yStr
}
var allMonths []time.Month = []time.Month{time.January, time.February, time.March, time.April, time.May, time.June,
time.July, time.August, time.September, time.October, time.November, time.December}
// Defines months series
type Months []time.Month
@@ -124,11 +120,7 @@ func (m Months) Contains(month time.Month) (result bool) {
// Loades Month elemnents from a string separated by sep.
func (m *Months) Parse(input, sep string) {
switch input {
case "*any":
*m = allMonths
case "*none": // Apier cannot receive empty string, hence using meta-tag
*m = []time.Month{}
case "":
case "*any", "": // Apier cannot receive empty string, hence using meta-tag
*m = []time.Month{}
default:
elements := strings.Split(input, sep)
@@ -143,9 +135,6 @@ func (m *Months) Parse(input, sep string) {
// Dumps the months in a serialized string, similar to the one parsed
func (m Months) Serialize(sep string) string {
if len(m) == 0 {
return "*none"
}
if reflect.DeepEqual(m, Months(allMonths)) {
return "*any"
}
var mStr string
@@ -159,8 +148,6 @@ func (m Months) Serialize(sep string) string {
return mStr
}
var allMonthDays []int = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
// Defines month days series
type MonthDays []int
@@ -195,9 +182,7 @@ func (md MonthDays) Contains(monthDay int) (result bool) {
// Parse MonthDay elements from string separated by sep.
func (md *MonthDays) Parse(input, sep string) {
switch input {
case "*any":
*md = allMonthDays
case "":
case "*any", "":
*md = []int{}
default:
elements := strings.Split(input, sep)
@@ -212,9 +197,6 @@ func (md *MonthDays) Parse(input, sep string) {
// Dumps the month days in a serialized string, similar to the one parsed
func (md MonthDays) Serialize(sep string) string {
if len(md) == 0 {
return "*none"
}
if reflect.DeepEqual(md, MonthDays(allMonthDays)) {
return "*any"
}
var mdsStr string
@@ -228,8 +210,6 @@ func (md MonthDays) Serialize(sep string) string {
return mdsStr
}
var allWeekDays []time.Weekday = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday}
// Defines week days series
type WeekDays []time.Weekday
@@ -263,9 +243,7 @@ func (wd WeekDays) Contains(weekDay time.Weekday) (result bool) {
func (wd *WeekDays) Parse(input, sep string) {
switch input {
case "*any":
*wd = allWeekDays
case "":
case "*any", "":
*wd = []time.Weekday{}
default:
elements := strings.Split(input, sep)
@@ -280,9 +258,6 @@ func (wd *WeekDays) Parse(input, sep string) {
// Dumps the week days in a serialized string, similar to the one parsed
func (wd WeekDays) Serialize(sep string) string {
if len(wd) == 0 {
return "*none"
}
if reflect.DeepEqual(wd, WeekDays(allWeekDays)) {
return "*any"
}
var wdStr string

View File

@@ -88,16 +88,10 @@ func TestYearsSerialize(t *testing.T) {
func TestMonthsSerialize(t *testing.T) {
mths := &Months{}
mString := mths.Serialize(";")
expectString := "*none"
expectString := "*any"
if expectString != mString {
t.Errorf("Expected: %s, got: %s", expectString, mString)
}
mths1 := Months(allMonths)
mString1 := mths1.Serialize(";")
expectString1 := "*any"
if expectString1 != mString1 {
t.Errorf("Expected: %s, got: %s", expectString1, mString1)
}
mths2 := &Months{time.January}
mString2 := mths2.Serialize(";")
expectString2 := "1"
@@ -115,16 +109,10 @@ func TestMonthsSerialize(t *testing.T) {
func TestMonthDaysSerialize(t *testing.T) {
mds := &MonthDays{}
mdsString := mds.Serialize(";")
expectString := "*none"
expectString := "*any"
if expectString != mdsString {
t.Errorf("Expected: %s, got: %s", expectString, mdsString)
}
mds1 := MonthDays(allMonthDays)
mdsString1 := mds1.Serialize(";")
expectString1 := "*any"
if expectString1 != mdsString1 {
t.Errorf("Expected: %s, got: %s", expectString1, mdsString1)
}
mds2 := &MonthDays{1}
mdsString2 := mds2.Serialize(";")
expectString2 := "1"
@@ -142,16 +130,10 @@ func TestMonthDaysSerialize(t *testing.T) {
func TestWeekDaysSerialize(t *testing.T) {
wds := &WeekDays{}
wdsString := wds.Serialize(";")
expectString := "*none"
expectString := "*any"
if expectString != wdsString {
t.Errorf("Expected: %s, got: %s", expectString, wdsString)
}
wds1 := WeekDays(allWeekDays)
wdsString1 := wds1.Serialize(";")
expectString1 := "*any"
if expectString1 != wdsString1 {
t.Errorf("Expected: %s, got: %s", expectString1, wdsString1)
}
wds2 := &WeekDays{time.Monday}
wdsString2 := wds2.Serialize(";")
expectString2 := "1"

File diff suppressed because one or more lines are too long

View File

@@ -117,13 +117,13 @@ func (s *FileScribe) load(filename string) error {
defer f.Close()
d := json.NewDecoder(f)
switch {
case filename == DESTINATIONS_FILE:
switch filename {
case DESTINATIONS_FILE:
if err := d.Decode(&s.destinations); err != nil {
return err
}
s.destinations.Sort()
case filename == RATING_PROFILES_FILE:
case RATING_PROFILES_FILE:
if err := d.Decode(&s.ratingProfiles); err != nil {
return err
}
@@ -140,12 +140,12 @@ func (s *FileScribe) save(filename string) error {
b := bufio.NewWriter(f)
defer b.Flush()
switch {
case filename == DESTINATIONS_FILE:
switch filename {
case DESTINATIONS_FILE:
if err := s.format(b, s.destinations); err != nil {
return err
}
case filename == RATING_PROFILES_FILE:
case RATING_PROFILES_FILE:
if err := s.format(b, s.ratingProfiles); err != nil {
return err
}

View File

@@ -54,15 +54,15 @@ func (s *MockScribe) Record(key string, obj interface{}) error {
}
func (s *MockScribe) save(filename string) error {
switch {
case filename == DESTINATIONS_FILE:
switch filename {
case DESTINATIONS_FILE:
s.DestBuf.Reset()
b := bufio.NewWriter(&s.DestBuf)
defer b.Flush()
if err := s.format(b, s.destinations); err != nil {
return err
}
case filename == RATING_PROFILES_FILE:
case RATING_PROFILES_FILE:
s.RpBuf.Reset()
b := bufio.NewWriter(&s.RpBuf)
defer b.Flush()