fixing calculate on day.
This commit is contained in:
parent
865ba96eb5
commit
0c049db317
|
@ -306,9 +306,10 @@ func CalculateMarketSecondsBetween(start, end, marketOpen, marketClose time.Time
|
|||
startEastern := start.In(Eastern())
|
||||
endEastern := end.In(Eastern())
|
||||
|
||||
startMarketOpen := NextMarketOpen(startEastern, marketOpen, isHoliday)
|
||||
startMarketClose := NextMarketClose(startEastern, marketClose, isHoliday)
|
||||
startMarketOpen := On(marketOpen, startEastern)
|
||||
startMarketClose := On(marketClose, startEastern)
|
||||
|
||||
if !IsWeekendDay(startMarketOpen.Weekday()) && !isHoliday(startMarketOpen) {
|
||||
if (startEastern.Equal(startMarketOpen) || startEastern.After(startMarketOpen)) && startEastern.Before(startMarketClose) {
|
||||
if endEastern.Before(startMarketClose) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor := NextMarketOpen(startMarketClose, marketOpen, isHoliday)
|
||||
for BeforeDate(cursor, endEastern) {
|
||||
|
|
|
@ -76,6 +76,17 @@ func TestCalculateMarketSecondsBetween(t *testing.T) {
|
|||
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) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package chart
|
|||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
|
@ -59,7 +58,7 @@ const (
|
|||
// DefaultDateHourFormat is the date format for hour timestamp formats.
|
||||
DefaultDateHourFormat = "01-02 3PM"
|
||||
// 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 = "%.2f"
|
||||
// DefaultPercentValueFormat is the default percent format.
|
||||
|
|
|
@ -111,8 +111,8 @@ func (mhr MarketHoursRange) String() string {
|
|||
func (mhr MarketHoursRange) Translate(value float64) int {
|
||||
valueTime := Float64ToTime(value)
|
||||
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)
|
||||
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
|
||||
translated := int((float64(valueDelta) / float64(totalSeconds)) * float64(mhr.Domain))
|
||||
return translated
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user