{"id":13454638,"url":"https://github.com/floatdrop/node-cctz","last_synced_at":"2025-03-15T13:30:50.033Z","repository":{"id":57195382,"uuid":"74818815","full_name":"floatdrop/node-cctz","owner":"floatdrop","description":"⚡️ Fast parsing, formatting and timezone manipulations for dates","archived":false,"fork":false,"pushed_at":"2018-01-15T06:11:13.000Z","size":90,"stargazers_count":59,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T01:31:42.772Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/floatdrop.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-26T10:23:54.000Z","updated_at":"2022-10-03T17:31:08.000Z","dependencies_parsed_at":"2022-09-16T10:50:30.347Z","dependency_job_id":null,"html_url":"https://github.com/floatdrop/node-cctz","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fnode-cctz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fnode-cctz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fnode-cctz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floatdrop%2Fnode-cctz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floatdrop","download_url":"https://codeload.github.com/floatdrop/node-cctz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243508116,"owners_count":20301949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:56.219Z","updated_at":"2025-03-15T13:30:49.645Z","avatar_url":"https://github.com/floatdrop.png","language":"C++","readme":"# node-cctz [![Build Status](https://travis-ci.org/floatdrop/node-cctz.svg?branch=master)](https://travis-ci.org/floatdrop/node-cctz)\n\n[CCTZ](https://github.com/google/cctz) is a C++ library for translating between absolute and civil times using the rules of a time zone.\n\n\n## Install\n\nYou will need C++11 compatible compiler to build this binding. For most systems this will work:\n\n```\n$ npm install --save cctz\n```\n\nIf you have Ubuntu 12.04, then install `clang-3.4` and set-up environment:\n\n```\n$ sudo apt-get install clang-3.4\n$ export CXX=clang++\n$ export npm_config_clang=1\n```\n\n\n## Usage\n\n```js\nconst {convert, format, CivilTime} = require('cctz');\n\nconst unix = convert(new CivilTime(2015, 9, 22, 9), 'America/Los_Angeles');\nconsole.log(format('Talk starts at %T %z (%Z)', unix, 'America/New_York'));\n\n// =\u003e Talk starts at 12:00:00 -0400 (EDT)\n```\n\n\n## API\n\n### convert(time, timezone)\n\nConverts `CivilTime` to unix timestamp and vice versa.\n\n##### time\n\nType: `CivilTime` or `number`\n\nIf `time` is `CivilTime`, then method returns Unix timestamp (without fractional part).\nOtherwise returns `CivilTime`.\n\n##### timezone\n\nType: `TimeZone` or `string`\n\nTimeZone objcet, that represents target timezone for converting.\n\n### format(format, unix, [timezone])\n\nReturns formatted unix timestamp according to timezone.\n\n##### format\n\nType: `string`\n\nFormat of output. See [strftime](http://www.cplusplus.com/reference/ctime/strftime/) documentation and [Google CCTZ](https://github.com/google/cctz/blob/6e09ceb/include/time_zone.h#L197) sources for syntax.\n\n##### unix\n\nType: `number`\n\nUnix timestamp in seconds (can have fractional part).\n\n##### timezone\n\nType: `TimeZone` or `string`\nDefault: local timezone\n\nTimeZone objcet, that represents target timezone for formatting.\n\n### parse(format, input, [timezone])\n\nParses `input` string according to `format` string (assuming `input` in `timezone`).\n\nReturns unix timestamp or `undefined` if parsing failed.\n\n##### format\n\nType: `string`\n\nFormat of `input` argument. See [strftime](http://www.cplusplus.com/reference/ctime/strftime/) documentation and [Google CCTZ](https://github.com/google/cctz/blob/6e09ceb/include/time_zone.h#232) sources for syntax.\n\n##### input\n\nType: `string`\n\nInput string to parse.\n\n##### timezone\n\nType: `TimeZone` or `string`\u003cbr\u003e\nDefault: Timezone from `input` or local timezone\n\nTimezone, that should be used in parse. Timezone can be part of input:\n\n```js\ncctz.parse('%Y-%m-%d %H:%M:%S %Ez', '2015-09-22 09:35:12+03:00');\n```\n\n### tz(name)\n\n\u003e Alias for `cctz.load_time_zone`\n\nUse this method instead `new TimeZone` – because it caches `TimeZone` objects inside.\n\nReturns `TimeZone` object.\n\n##### name\nType: `string`\n\nTimezone name, that should be loaded from `/usr/share/zoneinfo`.\n\n### now()\n\n\u003e Alias for `Math.floor(Date.now() / 1000)`\n\nReturns unix timestamp in seconds. All methods can accept timestamp with fractional milliseconds (if you need such accuracy).\n\n\n### CivilTime\n\nHolder for [`cctz::civil_second`](https://github.com/google/cctz/blob/6e09ceb/include/civil_time.h#L22) with getters and setters for properties.\n\n#### CivilTime(year = 1970, month = 1, day = 1, hour = 0, minute = 0, second = 0)\n\nCreates CivilTime object with next properties:\n\n- `year` – getter and setter\n- `month` – getter and setter [1:12]\n- `day` – getter and setter [1:31]\n- `hour` – getter and setter [0:23]\n- `minute` – getter and setter [0:59]\n- `second` – getter and setter [0:59]\n- `yearday` – only getter [1:356]\n- `weekday` – only getter [0:6]\n\n\u003e __Tip:__ Fastest way to add amount of time is to add number of seconds to unix timestamp.\n\n##### CivilTime.startOfYear()\n\nReturns new CivilTime object with start of year.\n\n##### CivilTime.startOfMonth()\n\nReturns new CivilTime object with start of month.\n\n##### CivilTime.startOfDay()\n\nReturns new CivilTime object with start of day.\n\n##### CivilTime.startOfHour()\n\nReturns new CivilTime object with start of hour.\n\n##### CivilTime.clone()\n\nReturns cloned CivilTime object.\n\n\n### TimeZone\n\nHolder for [`cctz::time_zone`](https://github.com/google/cctz/blob/6e09ceb/include/time_zone.h#L37).\n\n#### TimeZone(name)\n\nCreates __new__ object with TimeZone.\n\n##### TimeZone.lookup(unix)\n\nReturns [`cctz::absolute_lookup`](https://github.com/google/cctz/blob/6e09ceb/include/time_zone.h#L60) object.\n\n##### TimeZone.lookup(civiltime)\n\nReturns [`cctz::civil_lookup`](https://github.com/google/cctz/blob/6e09ceb/include/time_zone.h#L85) object.\n\n##### TimeZone.name\n\nName of TimeZone.\n\n\n## Benchmarks\n\n```\nFormat              (cctz) x 532,683 ops/sec ±2.80% (78 runs sampled)\n                    (Date) x 191,400 ops/sec ±2.59% (81 runs sampled)\n                (date-fns) x  91,772 ops/sec ±1.58% (85 runs sampled)\n                  (moment) x  56,508 ops/sec ±6.35% (76 runs sampled)\n\nParse               (cctz) x 1,105,353 ops/sec ±0.59% (86 runs sampled)\n                    (Date) x 1,200,218 ops/sec ±2.00% (82 runs sampled)\n                (date-fns) x   249,225 ops/sec ±5.00% (77 runs sampled)\n                  (moment) x    23,905 ops/sec ±1.91% (80 runs sampled)\n\nAdd hour            (cctz) x 6,123,083 ops/sec ±5.39% (82 runs sampled)\n                    (Date) x 3,604,915 ops/sec ±1.13% (69 runs sampled)\n                (date-fns) x 3,211,900 ops/sec ±2.28% (81 runs sampled)\n                  (moment) x   590,854 ops/sec ±8.48% (72 runs sampled)\n\nConvert Ut-\u003eTime    (cctz) x 653,305 ops/sec ±9.33% (68 runs sampled)\n                  (moment) x 144,580 ops/sec ±2.18% (83 runs sampled)\n\nConvert Time-\u003eUt    (cctz) x 987,437 ops/sec ±11.68% (70 runs sampled)\n                  (moment) x 154,492 ops/sec ±3.54% (82 runs sampled)\n```\n\nRun `npm i` and then `npm run bench`.\n\n## License\n\nMIT © [Vsevolod Strukchinsky](mailto://floatdrop@gmail.com)\n","funding_links":[],"categories":["Packages","包","目录","Date"],"sub_categories":["Date","日期","日期处理"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fnode-cctz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloatdrop%2Fnode-cctz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloatdrop%2Fnode-cctz/lists"}