tests.
This commit is contained in:
parent
e3ae7fd78f
commit
8fbb8d9775
3 changed files with 42 additions and 2 deletions
|
@ -310,7 +310,11 @@ func CalculateMarketSecondsBetween(start, end, marketOpen, marketClose time.Time
|
||||||
startMarketClose := NextMarketClose(startEastern, marketClose, isHoliday)
|
startMarketClose := NextMarketClose(startEastern, marketClose, isHoliday)
|
||||||
|
|
||||||
if (startEastern.Equal(startMarketOpen) || startEastern.After(startMarketOpen)) && startEastern.Before(startMarketClose) {
|
if (startEastern.Equal(startMarketOpen) || startEastern.After(startMarketOpen)) && startEastern.Before(startMarketClose) {
|
||||||
seconds += int64(startMarketClose.Sub(startEastern) / time.Second)
|
if endEastern.Before(startMarketClose) {
|
||||||
|
seconds += int64(endEastern.Sub(startEastern) / time.Second)
|
||||||
|
} else {
|
||||||
|
seconds += int64(startMarketClose.Sub(startEastern) / time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor := NextMarketOpen(startMarketClose, marketOpen, isHoliday)
|
cursor := NextMarketOpen(startMarketClose, marketOpen, isHoliday)
|
||||||
|
|
|
@ -106,6 +106,5 @@ func (mhr MarketHoursRange) Translate(value float64) int {
|
||||||
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTime, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTime, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
||||||
|
|
||||||
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
|
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
|
||||||
fmt.Printf("nyse translating: %s to %d ~= %d", valueTime.Format(time.RFC3339), deltaSeconds, valueDelta)
|
|
||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,3 +21,40 @@ func TestMarketHoursRangeGetDelta(t *testing.T) {
|
||||||
|
|
||||||
assert.NotZero(r.GetDelta())
|
assert.NotZero(r.GetDelta())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMarketHoursRangeTranslate(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
r := &MarketHoursRange{
|
||||||
|
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, date.Eastern()),
|
||||||
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, date.Eastern()),
|
||||||
|
MarketOpen: date.NYSEOpen,
|
||||||
|
MarketClose: date.NYSEClose,
|
||||||
|
HolidayProvider: date.IsNYSEHoliday,
|
||||||
|
Domain: 1000,
|
||||||
|
}
|
||||||
|
|
||||||
|
weds := time.Date(2016, 07, 20, 9, 30, 0, 0, date.Eastern())
|
||||||
|
|
||||||
|
assert.Equal(0, r.Translate(TimeToFloat64(r.Min)))
|
||||||
|
assert.Equal(400, r.Translate(TimeToFloat64(weds)))
|
||||||
|
assert.Equal(1000, r.Translate(TimeToFloat64(r.Max)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMarketHoursRangeGetTicks(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
r := &MarketHoursRange{
|
||||||
|
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, date.Eastern()),
|
||||||
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, date.Eastern()),
|
||||||
|
MarketOpen: date.NYSEOpen,
|
||||||
|
MarketClose: date.NYSEClose,
|
||||||
|
HolidayProvider: date.IsNYSEHoliday,
|
||||||
|
Domain: 1000,
|
||||||
|
}
|
||||||
|
|
||||||
|
ticks := r.GetTicks(TimeValueFormatter)
|
||||||
|
assert.NotEmpty(ticks)
|
||||||
|
assert.Equal(TimeToFloat64(r.Min), ticks[0].Value)
|
||||||
|
assert.NotEmpty(ticks[0].Label)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue