Skip to content

Commit ddaff24

Browse files
copperwallgr2m
authored andcommitted
feat(options): add timeZone option to constructor
1 parent 7faedb5 commit ddaff24

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class Octokit {
6262
requestDefaults.mediaType.previews = options.previews;
6363
}
6464

65+
if (options.timeZone) {
66+
requestDefaults.headers["time-zone"] = options.timeZone;
67+
}
68+
6569
if (options.auth) {
6670
if (typeof options.auth === "string") {
6771
requestDefaults.headers.authorization = withAuthorizationPrefix(

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Octokit } from ".";
66
export type OctokitOptions = {
77
auth?: string | AutenticationHook;
88
request?: OctokitRequestOptions;
9+
timeZone?: string;
910
[option: string]: any;
1011
};
1112

test/defaults.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,33 @@ describe("Octokit.defaults", () => {
6363
});
6464
});
6565

66+
it("Octokit.defaults({timeZone})", () => {
67+
const mock = fetchMock.sandbox().getOnce(
68+
"https://api.github.com/",
69+
{ ok: true },
70+
{
71+
headers: {
72+
accept: "application/vnd.github.v3+json",
73+
"user-agent": userAgent,
74+
"time-zone": "Europe/Amsterdam"
75+
}
76+
}
77+
);
78+
79+
const OctokitWithDefaults = Octokit.defaults({
80+
timeZone: "Europe/Amsterdam",
81+
request: {
82+
fetch: mock
83+
}
84+
});
85+
86+
const octokit = new OctokitWithDefaults();
87+
88+
return octokit.request("GET /").then(response => {
89+
expect(response.data).toStrictEqual({ ok: true });
90+
});
91+
});
92+
6693
it("Octokit.defaults({auth})", async () => {
6794
const mock = fetchMock.sandbox().getOnce(
6895
"https://api.github.com/app",

test/request.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ describe("octokit.request()", () => {
7575
});
7676
});
7777

78+
it("custom time zone", () => {
79+
const mock = fetchMock.sandbox().getOnce(
80+
"https://api.github.com/",
81+
{ ok: true },
82+
{
83+
headers: {
84+
accept: "application/vnd.github.v3+json",
85+
"user-agent": userAgent,
86+
"time-zone": "Europe/Amsterdam"
87+
}
88+
}
89+
);
90+
91+
const octokit = new Octokit({
92+
timeZone: "Europe/Amsterdam",
93+
request: {
94+
fetch: mock
95+
}
96+
});
97+
98+
return octokit.request("GET /").then(response => {
99+
expect(response.data).toStrictEqual({ ok: true });
100+
});
101+
});
102+
78103
it("previews", async () => {
79104
const mock = fetchMock
80105
.sandbox()

0 commit comments

Comments
 (0)