Skip to content

Commit

Permalink
chore(linting): fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo committed Sep 28, 2021
1 parent e33ae78 commit d0b6e9a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"editor.formatOnSave": true,
"eslint.packageManager": "npm",
"eslint.alwaysShowStatus": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[markdown]": {
"editor.formatOnSave": true
Expand Down
11 changes: 8 additions & 3 deletions lib/formatTimeZone.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ export default function format(
}

function getOffsetString(offsetInMinutes) {
const absOffsetInMinutes = Math.abs(offsetInMinutes)
const [hours, minutes] = [Math.floor(absOffsetInMinutes / 60), absOffsetInMinutes % 60].map(v => v.toString().padStart(2, '0'))
const durationInHoursMinutes = `${hours}:${minutes}`
const absOffsetInMinutes = Math.abs(offsetInMinutes);
const [hours, minutes] = [
Math.floor(absOffsetInMinutes / 60),
absOffsetInMinutes % 60,
].map((v) => {
return v.toString().padStart(2, "0");
});
const durationInHoursMinutes = `${hours}:${minutes}`;

return `${offsetInMinutes >= 0 ? "+" : "-"}${durationInHoursMinutes}`;
}
2 changes: 1 addition & 1 deletion lib/getTimeZones.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rawTimeZones from "../raw-time-zones.json";

import formatTimeZone from "./formatTimeZone.js";
import {getZoneOffset} from "./utils/timeZone.js";
import { getZoneOffset } from "./utils/timeZone.js";

export default function getTimeZones(opts) {
const includeUtc = !!opts && opts.includeUtc;
Expand Down
29 changes: 19 additions & 10 deletions lib/utils/timeZone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
const ianaRegex = /^[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?$/;
// Most of the code here is from Luxon
// Copyright 2019 JS Foundation and other contributors

// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

const ianaRegex =
/^[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?$/;

const typeToPos = {
year: 0,
Expand Down Expand Up @@ -27,7 +37,7 @@ function partsOffset(dtf, date) {
const { type, value } = formatted[i];
const pos = typeToPos[type];

if (typeof pos !== 'undefined') {
if (typeof pos !== "undefined") {
filled[pos] = parseInt(value, 10);
}
}
Expand Down Expand Up @@ -56,7 +66,7 @@ function objToLocalTS(obj) {
obj.hour,
obj.minute,
obj.second,
obj.millisecond
obj.millisecond,
);

// for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
Expand All @@ -69,22 +79,22 @@ function objToLocalTS(obj) {

export function getZoneOffset(timeZoneName) {
if (!isValidIanaSpecifier(timeZoneName)) {
return false
return false;
}

const date = new Date(Date.now());

let dtf
let dtf;

try {
dtf = makeDTF(timeZoneName);
} catch(_) {
return false
} catch (_) {
return false;
}

const [year, month, day, hour, minute, second] = dtf.formatToParts
? partsOffset(dtf, date)
: hackyOffset(dtf, date);
? partsOffset(dtf, date)
: hackyOffset(dtf, date);

const asUTC = objToLocalTS({
year,
Expand All @@ -101,4 +111,3 @@ export function getZoneOffset(timeZoneName) {
asTS -= over >= 0 ? over : 1000 + over;
return (asUTC - asTS) / (60 * 1000);
}

48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"main",
"next"
]
},
"renovate": {
"extends": [
"config:js-lib",
Expand Down

0 comments on commit d0b6e9a

Please sign in to comment.