Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 28, 2023
2 parents 4b5c6f6 + 53c5a89 commit 0159395
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 176 deletions.
43 changes: 43 additions & 0 deletions .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

name: "\U0001F41E Bug report"
about: Something is not working as it should
title: "\[fix] DESCRIPTIVE TITLE"
labels: bug
assignees: ''

---

#### Describe the bug

* Node.js version:
* OS & version:

<!-- A clear and concise description of what the bug is. -->

#### Actual behavior

...

#### Expected behavior

...

#### Code to reproduce

```js
...
```

<!--
We encourage you to submit a pull request with a failing test:
- This will make it more likely for us to prioritize your issue.
- It's a good way to prove that the issue is related to Got and not your code.
Example: https://github.com/avajs/ava/blob/master/docs/01-writing-tests.md#failing-tests
-->

#### Checklist

* [ ] I have read the documentation.
* [ ] I have tried my code with the latest version of Node.js and @breejs/later.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/--feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

name: "⭐ Feature request"
about: Suggest an idea for Bree
title: "\[feat] DESCRIPTIVE TITLE"
labels: enhancement
assignees: ''

---

#### What problem are you trying to solve?

...

#### Describe the feature

...

<!-- Include a usage example of the feature. If the feature is currently possible with a workaround, include that too. -->

#### Checklist

* [ ] I have read the documentation and made sure this feature doesn't already exist.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/--question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

name: "❓ Question"
about: Something is unclear or needs to be discussed
title: "\[discussion] DESCRIPTIVE TITLE"
labels: question
assignees: ''

---

#### What would you like to discuss?

...

#### Checklist

* [ ] I have read the documentation.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on: [push, pull_request]

jobs:
test-coverage:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest
node_version:
- 10
- 12
- 14
- 16

name: Node ${{ matrix.node_version }} on ${{ matrix.os }}

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn --frozen-lockfile

- name: Run tests
run: yarn test-coverage

- name: Uninstall yarn
if: always()
run: npm uninstall -g yarn
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @breejs/later

[![build status](https://img.shields.io/travis/com/breejs/later.svg)](https://travis-ci.com/breejs/later)
[![build status](https://github.com/breejs/later/actions/workflows/ci.yml/badge.svg)](https://github.com/breejs/later/actions/workflows/ci.yml)
[![code coverage](https://img.shields.io/codecov/c/github/breejs/later.svg)](https://codecov.io/gh/breejs/later)
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
Expand All @@ -25,7 +25,7 @@

## Features

Types of schedules supported by _Later_:
Types of schedules supported by *Later*:

* Run a report on the last day of every month at 12 AM except in December
* Install patches on the 2nd Tuesday of every month at 4 AM
Expand Down Expand Up @@ -97,7 +97,7 @@ Assuming you are using [browserify][], [webpack][], [rollup][], or another bundl
[MIT](LICENSE) © BunKat


##
##

[npm]: https://www.npmjs.com/

Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@breejs/later",
"description": "Maintained fork of later. Determine later (or previous) occurrences of recurring schedules",
"version": "4.0.3",
"version": "4.1.0",
"author": "BunKat <bill@levelstory.com>",
"bugs": {
"url": "https://github.com/breejs/later/issues",
Expand All @@ -12,32 +12,32 @@
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
"yrambler2001 <yrambler2001@gmail.com> (https://yrambler2001.me/)"
],
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"babelify": "^10.0.0",
"benchmark": "*",
"benchmark": "^2.1.4",
"browserify": "^16.5.2",
"codecov": "latest",
"cross-env": "latest",
"cross-env": "^7.0.3",
"eslint": "^7.7.0",
"eslint-config-xo-lass": "latest",
"eslint-config-xo-lass": "^2.0.1",
"eslint-plugin-compat": "^3.8.0",
"eslint-plugin-node": "^11.1.0",
"fixpack": "latest",
"husky": "latest",
"lint-staged": "latest",
"mocha": "*",
"nyc": "latest",
"remark-cli": "latest",
"remark-preset-github": "latest",
"fixpack": "^4.0.0",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"remark-cli": "11",
"remark-preset-github": "^4.0.4",
"rimraf": "^5.0.5",
"semver": "^7.3.2",
"should": ">=13.2.3",
"should": "^13.2.3",
"sinon": "^11.1.2",
"tinyify": "^3.0.0",
"xo": "^0.33.0"
},
Expand Down Expand Up @@ -155,7 +155,7 @@
"build:clean": "rimraf lib dist",
"build:dist": "npm run browserify && npm run minify",
"build:lib": "babel --config-file ./.lib.babelrc src --out-dir lib",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov",
"lint": "yarn run lint:js && yarn run lint:md && yarn run lint:lib && yarn run lint:dist",
"lint:dist": "eslint --no-inline-config -c .dist.eslintrc dist",
"lint:js": "xo",
Expand All @@ -164,7 +164,7 @@
"minify": "cross-env NODE_ENV=production browserify src/index.js -o dist/later.min.js -s later -g [ babelify --configFile ./.dist.babelrc ] -p tinyify",
"nyc": "cross-env NODE_ENV=test nyc mocha test/**/*-test.js --reporter dot",
"pretest": "yarn run build && yarn run lint",
"test": "cross-env NODE_ENV=test mocha test/**/*-test.js --reporter dot",
"test": "cross-env NODE_ENV=test mocha test/**/*-test.js --reporter dot --exit",
"test-coverage": "cross-env NODE_ENV=test nyc yarn run test"
},
"unpkg": "dist/later.min.js",
Expand Down
74 changes: 60 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,16 +1189,45 @@ later.schedule = function (sched) {
};
};

later.setTimeout = function (fn, sched) {
later.setTimeout = function (fn, sched, timezone) {
const s = later.schedule(sched);
let t;
if (fn) {
scheduleTimeout();
}

function scheduleTimeout() {
const now = Date.now();
const next = s.next(2, now);
const date = new Date();
const now = date.getTime();

const next = (() => {
if (!timezone || ['local', 'system'].includes(timezone)) {
return s.next(2, now);
}

const localOffsetMillis = date.getTimezoneOffset() * 6e4;
const offsetMillis = getOffset(date, timezone);

// Specified timezone has the same offset as local timezone.
// ie. America/New_York = America/Nassau = GMT-4
if (offsetMillis === localOffsetMillis) {
return s.next(2, now);
}

// Offsets differ, adjust current time to match what
// it should've been for the specified timezone.
const adjustedNow = new Date(now + localOffsetMillis - offsetMillis);

return (s.next(2, adjustedNow) || /* istanbul ignore next */ []).map(
(sched) => {
// adjust scheduled times to match their intended timezone
// ie. scheduled = 2021-08-22T11:30:00.000-04:00 => America/New_York
// intended = 2021-08-22T11:30:00.000-05:00 => America/Mexico_City
return new Date(sched.getTime() + offsetMillis - localOffsetMillis);
}
);
})();

if (!next[0]) {
t = undefined;
return;
Expand All @@ -1209,12 +1238,11 @@ later.setTimeout = function (fn, sched) {
diff = next[1] ? next[1].getTime() - now : 1e3;
}

if (diff < 2147483647) {
t = setTimeout(fn, diff);
} else {
t = setTimeout(scheduleTimeout, 2147483647);
}
}
t =
diff < 2147483647
? setTimeout(fn, diff)
: setTimeout(scheduleTimeout, 2147483647);
} // scheduleTimeout()

return {
isDone() {
Expand All @@ -1224,19 +1252,20 @@ later.setTimeout = function (fn, sched) {
clearTimeout(t);
}
};
};
}; // setTimeout()

later.setInterval = function (fn, sched) {
later.setInterval = function (fn, sched, timezone) {
if (!fn) {
return;
}

let t = later.setTimeout(scheduleTimeout, sched);
let t = later.setTimeout(scheduleTimeout, sched, timezone);
let done = t.isDone();
function scheduleTimeout() {
/* istanbul ignore else */
if (!done) {
fn();
t = later.setTimeout(scheduleTimeout, sched);
t = later.setTimeout(scheduleTimeout, sched, timezone);
}
}

Expand All @@ -1249,7 +1278,7 @@ later.setInterval = function (fn, sched) {
t.clear();
}
};
};
}; // setInterval()

later.date = {};
later.date.timezone = function (useLocalTime) {
Expand Down Expand Up @@ -2121,4 +2150,21 @@ later.parse.text = function (string) {
return parseScheduleExpr(string.toLowerCase());
};

function getOffset(date, zone) {
const d = date
.toLocaleString('en-US', {
hour12: false,
timeZone: zone,
timeZoneName: 'short'
}) //=> ie. "8/22/2021, 24:30:00 EDT"
.match(/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/)
.map((n) => (n.length === 1 ? '0' + n : n));

const zdate = new Date(
`${d[3]}-${d[1]}-${d[2]}T${d[4].replace('24', '00')}:${d[5]}:${d[6]}Z`
);

return date.getTime() - zdate.getTime();
} // getOffset()

module.exports = later;

0 comments on commit 0159395

Please sign in to comment.