当前位置: 首页>>代码示例>>C++>>正文


C++ date::year_month_day方法代码示例

本文整理汇总了C++中date::year_month_day方法的典型用法代码示例。如果您正苦于以下问题:C++ date::year_month_day方法的具体用法?C++ date::year_month_day怎么用?C++ date::year_month_day使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在date的用法示例。


在下文中一共展示了date::year_month_day方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: to_tm

//! Converts a date to a tm struct. Throws out_of_range exception if date is a special value
inline
std::tm to_tm(const date& d)
{
    if (d.is_special())
    {
        std::string s = "tm unable to handle ";
        switch (d.as_special())
        {
        case date_time::not_a_date_time:
            s += "not-a-date-time value";
            break;
        case date_time::neg_infin:
            s += "-infinity date value";
            break;
        case date_time::pos_infin:
            s += "+infinity date value";
            break;
        default:
            s += "a special date value";
            break;
        }
        boost::throw_exception(std::out_of_range(s));
    }

    std::tm datetm;
    std::memset(&datetm, 0, sizeof(datetm));
    boost::gregorian::date::ymd_type ymd = d.year_month_day();
    datetm.tm_year = ymd.year - 1900;
    datetm.tm_mon = ymd.month - 1;
    datetm.tm_mday = ymd.day;
    datetm.tm_wday = d.day_of_week();
    datetm.tm_yday = d.day_of_year() - 1;
    datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst
    return datetm;
}
开发者ID:HackLinux,项目名称:Free-Download-Manager-vs2010,代码行数:36,代码来源:conversion.hpp

示例2: to_tm

  //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value
  inline
  std::tm to_tm(const date& d) 
  {
    if(d.is_pos_infinity() || d.is_neg_infinity() || d.is_not_a_date()){
      std::string s = "tm unable to handle date value of ";
#if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
      s += to_simple_string(d);
#else
      std::ostringstream ss;
      ss << d;
      s += ss.str();
#endif // USE_DATE_TIME_PRE_1_33_FACET_IO
      boost::throw_exception(std::out_of_range(s));
    }
    std::tm datetm;
    boost::gregorian::date::ymd_type ymd = d.year_month_day();
    datetm.tm_year = ymd.year-1900; 
    datetm.tm_mon = ymd.month-1; 
    datetm.tm_mday = ymd.day;
    datetm.tm_wday = d.day_of_week();
    datetm.tm_yday = d.day_of_year()-1;
    datetm.tm_hour = datetm.tm_min = datetm.tm_sec = 0;
    datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst
    return datetm;
  }
开发者ID:BioinformaticsArchive,项目名称:MulRFRepo,代码行数:26,代码来源:conversion.hpp

示例3: quote

std::unique_ptr<quoteVector_t>
YahooFDS::get_historical_prices(const std::string &symbol,
                                    date &start,
                                    date &end)
{
    //quoteVector_t *quotes = new quoteVector_t;
    auto quotes = new quoteVector_t;
    auto start_d = start.year_month_day();
    auto end_d = end.year_month_day();
    std::vector<std::string> quoteStrings;
    std::ostringstream url;
    url << "http://ichart.yahoo.com/table.csv?s=" << symbol << "&d=" \
                                                << end_d.month - 1 << "&e=" \
                                                << end_d.day << "&f=" \
                                                << end_d.year << "&a=" \
                                                << start_d.month - 1 << "&b=" \
                                                << start_d.day << "&c=" \
                                                << start_d.year << "&ignore=.csv";
    
    // split the response into lines
    boost:split(quoteStrings, (const std::string &)request(url.str()), boost::is_any_of("\n"),boost::token_compress_on); 
    
    // Remove header line
    quoteStrings.erase(quoteStrings.begin());
      
    for (auto it = quoteStrings.rbegin(); it < quoteStrings.rend(); ++it)
    {
        // Ensure we have a valid quote here. 38 is presumably the shortest possible quote. 35 is magic as fuck (MAF).
        if ((*it).length() > 35)
        {
            std::vector<std::string> temp;
            boost::split(temp, *it, boost::is_any_of(", "));
            HistoricalQuote quote(symbol,
                                temp.at(0),
                                atof(temp.at(1).c_str()),
                                atof(temp.at(2).c_str()),
                                atof(temp.at(3).c_str()),
                                atof(temp.at(4).c_str()),
                                atol(temp.at(5).c_str()),
                                atof(temp.at(6).c_str()));
                                
            // Make it rain!
            quotes->push_back(quote);
        }
    }
    return std::unique_ptr<quoteVector_t>(std::move(quotes));
}
开发者ID:547872495,项目名称:stocks,代码行数:47,代码来源:yahooFDS.cpp

示例4:

 inline std::basic_string<charT> to_sql_string_type(const date& d) 
 {
   date::ymd_type ymd = d.year_month_day();
   std::basic_ostringstream<charT> ss;
   ss << ymd.year << "-"
      << std::setw(2) << std::setfill(ss.widen('0')) 
      << ymd.month.as_number() //solves problem with gcc 3.1 hanging
      << "-"
      << std::setw(2) << std::setfill(ss.widen('0')) 
      << ymd.day;
   return ss.str();
 }
开发者ID:ngzHappy,项目名称:cpc2,代码行数:12,代码来源:formatters.hpp

示例5:

 inline std::string to_sql_string(const date& d) 
 {
   date::ymd_type ymd = d.year_month_day();
   std::ostringstream ss;
   ss << ymd.year << "-"
      << std::setw(2) << std::setfill('0') 
      << ymd.month.as_number() //solves problem with gcc 3.1 hanging
      << "-"
      << std::setw(2) << std::setfill('0') 
      << ymd.day;
   return ss.str();
 }
开发者ID:Niko-r,项目名称:geofeatures,代码行数:12,代码来源:formatters_limited.hpp


注:本文中的date::year_month_day方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。