技术控

    今日:71| 主题:57652
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Google CCTZ binding for Node.JS

[复制链接]
释怀°Believe 投递于 2016-11-30 02:31:18
126 0
node-cctz  

  Because sometimes Moment.JS is slow
  CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone.  
  Usage

  1. const cctz = require('cctz');
  2. const lax = cctz.load_time_zone('America/Los_Angeles');
  3. const tp = cctz.convert(new cctz.CivilSecond(2015, 9, 22, 9), lax);
  4. const nyc = cctz.load_time_zone('America/New_York');
  5. console.log(cctz.format('Talk starts at %T %z (%Z)', tp, nyc));
  6. // => Talk starts at 12:00:00 -0400 (EDT)
复制代码
API

  cctz.load_time_zone(name)

  Returns TimeZone object for time zone with    namefrom    /usr/share/zoneinfo.  
  Pro-tip: Cache TimeZone objects.  
  cctz.utc_time_zone()

  Returns    UTCTimeZone object.  
  cctz.local_time_zone()

  Returns    localtimeTimeZone object.  
  cctz.parse(format, input, timezone)

  Parses    inputstring according to    formatstring (assuming    inputin    timezone).  
  Returns TimePoint object.
  cctz.format(format, timepoint, timezone)

  Formats TimePoint    timepointobject according to    formatin    timezone.  
  Returns string.
  cctz.convert(timepoint, timezone)

  Returns CivilSecond object from    timepointin    timezone.  
  cctz.convert(civilsecond, timezone)

  Returns TimePoint object from    civilsecondin    timezone.  
  TimePoint

  Holder for          std::chrono::time_point    .  
  TimePoint(unix)

  Creates TimePoint from Unix timestamp (in milliseconds).
  TimePoint.unix

  Returns Unix timestamp in milliseconds.
  CivilSecond

  Holder for          cctz::civil_second    with getters and setters for properties.  
  CivilSecond(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0)

  Creates CivilSecond object.
  CivilSecond.year

  CivilSecond.month

  CivilSecond.day

  CivilSecond.hour

  CivilSecond.minute

  CivilSecond.second

  CivilSecond.yearday (only getter)

  CivilSecond.weekday (only getter)

  TimeZone

  Holder for          cctz::time_zone    .  
  TimeZone(name)

  Same as    load_time_zone.  
  TimeZone.lookup(timepoint)

  Returns          cctz::absolute_lookup    object.  
  TimeZone.lookup(civilsecond)

  Returns          cctz::civil_lookup    object.  
  TimeZone.name

  Name of TimeZone.
  Benchmarks

  1. Parse-Format      (Date) x 590,555 ops/sec ±1.64% (83 runs sampled)
  2. Parse-Format      (cctz) x 505,249 ops/sec ±3.95% (78 runs sampled)
  3. Parse-Format    (moment) x 19,295 ops/sec ±2.12% (81 runs sampled)
  4. Increment hour    (Date) x 15,962 ops/sec ±6.53% (79 runs sampled)
  5. Increment hour    (cctz) x 5,718 ops/sec ±1.66% (85 runs sampled)
  6. Increment hour  (moment) x 600 ops/sec ±1.58% (84 runs sampled)
复制代码
Run    npm iand then    npm run bench.  
  License

  MIT ©    Vsevolod Strukchinsky



上一篇:Write You A Scheme version 2.0
下一篇:upper.io - database access
我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表