gitee.com/quant1x/engine@v1.8.4/cache/datetime.go (about)

     1  package cache
     2  
     3  import (
     4  	"gitee.com/quant1x/exchange"
     5  	"time"
     6  )
     7  
     8  const (
     9  	TDX_FORMAT_PROTOCOL_DATE = "20060102"   // 通达信协议的日期字符串格式
    10  	CACHE_DATE               = "20060102"   // 缓存日期
    11  	INDEX_DATE               = "2006-01-02" // 索引日期格式
    12  	TDX_DATE                 = "20060102"   // 通达信日期
    13  	YearOnly                 = "2006"       // 仅年份
    14  	TimeStampMilli           = "2006-01-02 15:04:05.000"
    15  	TimeStampMicro           = "2006-01-02 15:04:05.000000"
    16  	TimeStampNano            = "2006-01-02 15:04:05.000000000"
    17  )
    18  
    19  func Today() string {
    20  	now := time.Now()
    21  	return now.Format(CACHE_DATE)
    22  }
    23  
    24  //// CorrectDate 矫正日期, 统一格式: 20060102
    25  //func CorrectDate(date string) string {
    26  //	dt, err := api.ParseTime(date)
    27  //	if err != nil {
    28  //		return Today()
    29  //	}
    30  //	date = dt.Format(CACHE_DATE)
    31  //	return date
    32  //}
    33  
    34  // CorrectDate 校正日期
    35  func CorrectDate(date string) (cacheDate, resourcesDate string) {
    36  	cacheDate = exchange.FixTradeDate(date)
    37  	dates := exchange.LastNDate(cacheDate, 1)
    38  	if len(dates) == 0 {
    39  		// TODO: 存在一定概率的坑, 比如1990-12-19执行
    40  		resourcesDate = cacheDate
    41  	} else {
    42  		resourcesDate = dates[0]
    43  	}
    44  	cacheDate = exchange.NextTradeDate(resourcesDate)
    45  	return
    46  }
    47  
    48  // DefaultCanReadDate 获取默认可以读缓存文件的日期
    49  func DefaultCanReadDate() string {
    50  	dateOfReadingData := exchange.GetCurrentDate()
    51  	return dateOfReadingData
    52  }
    53  
    54  // DefaultCanUpdateDate 获取默认可以更新缓存文件的日期
    55  func DefaultCanUpdateDate() string {
    56  	currentDate := exchange.GetCurrentDate()
    57  	dateOfUpdatingData := exchange.NextTradeDate(currentDate)
    58  	return dateOfUpdatingData
    59  }
    60  
    61  // DefaultCanUpdateDate 获取默认可以更新缓存文件的日期
    62  func testDefaultCanUpdateDate() string {
    63  	dateOfUpdatingData := exchange.GetCurrentlyDay()
    64  	return dateOfUpdatingData
    65  }