fixing calculate on day.
This commit is contained in:
parent
865ba96eb5
commit
0c049db317
4 changed files with 23 additions and 11 deletions
|
@ -306,9 +306,10 @@ func CalculateMarketSecondsBetween(start, end, marketOpen, marketClose time.Time
|
||||||
startEastern := start.In(Eastern())
|
startEastern := start.In(Eastern())
|
||||||
endEastern := end.In(Eastern())
|
endEastern := end.In(Eastern())
|
||||||
|
|
||||||
startMarketOpen := NextMarketOpen(startEastern, marketOpen, isHoliday)
|
startMarketOpen := On(marketOpen, startEastern)
|
||||||
startMarketClose := NextMarketClose(startEastern, marketClose, isHoliday)
|
startMarketClose := On(marketClose, startEastern)
|
||||||
|
|
||||||
|
if !IsWeekendDay(startMarketOpen.Weekday()) && !isHoliday(startMarketOpen) {
|
||||||
if (startEastern.Equal(startMarketOpen) || startEastern.After(startMarketOpen)) && startEastern.Before(startMarketClose) {
|
if (startEastern.Equal(startMarketOpen) || startEastern.After(startMarketOpen)) && startEastern.Before(startMarketClose) {
|
||||||
if endEastern.Before(startMarketClose) {
|
if endEastern.Before(startMarketClose) {
|
||||||
seconds += int64(endEastern.Sub(startEastern) / time.Second)
|
seconds += int64(endEastern.Sub(startEastern) / time.Second)
|
||||||
|
@ -316,6 +317,7 @@ func CalculateMarketSecondsBetween(start, end, marketOpen, marketClose time.Time
|
||||||
seconds += int64(startMarketClose.Sub(startEastern) / time.Second)
|
seconds += int64(startMarketClose.Sub(startEastern) / time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cursor := NextMarketOpen(startMarketClose, marketOpen, isHoliday)
|
cursor := NextMarketOpen(startMarketClose, marketOpen, isHoliday)
|
||||||
for BeforeDate(cursor, endEastern) {
|
for BeforeDate(cursor, endEastern) {
|
||||||
|
|
|
@ -76,6 +76,17 @@ func TestCalculateMarketSecondsBetween(t *testing.T) {
|
||||||
assert.Equal(shouldbe, CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, IsNYSEHoliday))
|
assert.Equal(shouldbe, CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, IsNYSEHoliday))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCalculateMarketSecondsBetween1D(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
start := time.Date(2016, 07, 22, 9, 45, 0, 0, Eastern())
|
||||||
|
end := time.Date(2016, 07, 22, 15, 45, 0, 0, Eastern())
|
||||||
|
|
||||||
|
shouldbe := 6 * 60 * 60
|
||||||
|
|
||||||
|
assert.Equal(shouldbe, CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, IsNYSEHoliday))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCalculateMarketSecondsBetweenLTM(t *testing.T) {
|
func TestCalculateMarketSecondsBetweenLTM(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package chart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
|
@ -59,7 +58,7 @@ const (
|
||||||
// DefaultDateHourFormat is the date format for hour timestamp formats.
|
// DefaultDateHourFormat is the date format for hour timestamp formats.
|
||||||
DefaultDateHourFormat = "01-02 3PM"
|
DefaultDateHourFormat = "01-02 3PM"
|
||||||
// DefaultDateMinuteFormat is the date format for minute range timestamp formats.
|
// DefaultDateMinuteFormat is the date format for minute range timestamp formats.
|
||||||
DefaultDateMinuteFormat = time.Kitchen
|
DefaultDateMinuteFormat = "01-02 3:04PM"
|
||||||
// DefaultFloatFormat is the default float format.
|
// DefaultFloatFormat is the default float format.
|
||||||
DefaultFloatFormat = "%.2f"
|
DefaultFloatFormat = "%.2f"
|
||||||
// DefaultPercentValueFormat is the default percent format.
|
// DefaultPercentValueFormat is the default percent format.
|
||||||
|
|
|
@ -111,8 +111,8 @@ func (mhr MarketHoursRange) String() string {
|
||||||
func (mhr MarketHoursRange) Translate(value float64) int {
|
func (mhr MarketHoursRange) Translate(value float64) int {
|
||||||
valueTime := Float64ToTime(value)
|
valueTime := Float64ToTime(value)
|
||||||
valueTimeEastern := valueTime.In(date.Eastern())
|
valueTimeEastern := valueTime.In(date.Eastern())
|
||||||
deltaSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.Max, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
totalSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.Max, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
||||||
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTimeEastern, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTimeEastern, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
|
||||||
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
|
translated := int((float64(valueDelta) / float64(totalSeconds)) * float64(mhr.Domain))
|
||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue