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


C++ TimeZone::getHours方法代码示例

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


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

示例1: append_timezone

static void append_timezone( char component, TimeZone const &tz,
                             modifier const &mod, zstring *dest ) {
  ascii::itoa_buf_type buf;
  zstring format, tmp;
  bool has_grouping_separators;

  if ( mod.first.format.empty() ) {
    format = "01:01";
    has_grouping_separators = true;
  } else {
    format = mod.first.format;
    has_grouping_separators = mod.first.has_grouping_separators;
  }

  int hour = tz.getHours();
  int const min  = std::abs( tz.getMinutes() );

  switch ( mod.first.type ) {
    case modifier::NAME:
      //
      // XQuery F&O 3.0: 9.8.4.2: If the first presentation modifier is N, then
      // the timezone is output (where possible) as a timezone name, for
      // example EST or CET. The same timezone offset has different names in
      // different places; it is therefore recommended that this option should
      // be used only if a country code or Olson timezone name is supplied in
      // the $place argument. In the absence of this information, the
      // implementation may apply a default, for example by using the timezone
      // names that are conventional in North America. If no timezone name can
      // be identified, the timezone offset is output using the fallback format
      // +01:01.
      //
      if ( !min )
        switch ( hour ) {
          case  0: tmp += "GMT"; goto append;
          case -5: tmp += "EST"; goto append;
          case -6: tmp += "CST"; goto append;
          case -7: tmp += "MST"; goto append;
          case -8: tmp += "PST"; goto append;
        }
      // TODO: use Olson timezone names
      goto fallback;

    case modifier::military_tz:
      //
      // Ibid: If the first presentation modifier is Z, then the timezone is
      // formatted as a military timezone letter, using the convention Z =
      // +00:00, A = +01:00, B = +02:00, ..., M = +12:00, N = -01:00, O =
      // -02:00, ... Y = -12:00.
      //
      if ( !tz ) {
        //
        // Ibid: The letter J (meaning local time) is used in the case of a
        // value that does not specify a timezone offset.
        //
        tmp += 'J';
        break;
      }
      if ( hour >= -12 && hour <= 12 && !min ) {
        tmp += time::get_military_tz( hour );
        break;
      }
      //
      // Ibid: Timezone offsets that have no representation in this system
      // (for example Indian Standard Time, +05:30) are output as if the
      // format 01:01 had been requested.
      //
      // no break;

fallback:
      format = "01:01";
      has_grouping_separators = true;
      // no break;

    default:
      if ( component == 'z' ) {
        //
        // Ibid: When the component specifier is z, the output is the same as
        // for component specifier Z, except that it is prefixed by the
        // characters GMT or some localized equivalent. The prefix is omitted,
        // however, in cases where the timezone is identified by name rather
        // than by a numeric offset from UTC.
        //
        tmp = "GMT";
      }

      if ( mod.second.at == modifier::traditional && !hour && !min ) {
        //
        // Ibid: If the first presentation modifier is numeric, in any of the
        // above formats, and the second presentation modifier is t, then a
        // zero timezone offset (that is, UTC) is output as Z instead of a
        // signed numeric value.
        //
        tmp += 'Z';
        break;
      }

      if ( tz < 0 )
        tmp += '-', hour = std::abs( hour );
      else
        tmp += '+';
//.........这里部分代码省略.........
开发者ID:zorba-processor,项目名称:zorba,代码行数:101,代码来源:format_dateTime.cpp


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