Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE ui] Timezone override support #135

Merged
merged 6 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,22 @@ It fetches and refreshes PagerDuty schedules in the background using secret Page
PagerDuty uses [Gravatar](https://en.gravatar.com/) to manage profile photos.
If you already have a Gravatar account, you can attach your PagerDuty login email to this account.

### How can I set a custom timezone?
By default From and To fields are displayed in the timezone of the schedule.
You can override this by adding `?timezone=value` to schedule URL. Use any timezone value [supported by luxon](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Examples:
* Local to the client browser: /v1/schedules/PJ1P5JQ.html**?timezone=local**
* UTC: /v1/schedules/PJ1P5JQ.html**?timezone=UTC**
* Any UTC offset: /v1/schedules/PJ1P5JQ.html**?timezone=UTC+5**
* Any [IANA Timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones): /v1/schedules/PJ1P5JQ.html**?timezone=Europe/Kiev**

## Contributing
[Contribution guide](https://github.com/sergiitk/pagerbeauty/tree/master/CONTRIBUTING.md) and step-by-step local development instructions.
The source code of [Pager Beauty](https://github.com/sergiitk/pagerbeauty) is maintained by [@sergiitk](https://github.com/sergiitk).
It's an Open Source project under MIT License. Contributions are welcomed. Follow the usual GitHub Pull Request process. [Be nice.](https://github.com/sergiitk/pagerbeauty/tree/master/CODE_OF_CONDUCT.md)

## Roadmap
- `2019-04-01 – 2019-10-01`: Maintentnce mode: security and depdendency updates. Minor features, see Version 1.1.
- `2019-10-01 — 2020-03-01`: Major features, see Version 2.0.
- `2019-04-01 – 2019-10-01`: Maintentnce mode: security and depdendency updates.
- `2020-10-01 — 2021-03-01`: Major features, see Version 2.0.

#### Version 1.0

Expand All @@ -194,9 +202,6 @@ It's an Open Source project under MIT License. Contributions are welcomed. Follo
- [x] Make on-call view red during an active incident
- [x] HTTP authentication bypass support for embeds

#### Version 1.1
- [ ] [#102](https://github.com/sergiitk/pagerbeauty/issues/102) Ability to use browser local time

#### Version 2.0
- [ ] Built-in SSL Support
- [ ] Next on duty
Expand Down
17 changes: 16 additions & 1 deletion src/assets/javascripts/views/OnCallViews.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,24 @@ export class OnCallDateTimeView extends React.Component {
render() {
const { date, timezone } = this.props;
let dateInTz = date;
if (timezone) {

const urlParams = new URLSearchParams(window.location.search);
const tzOverride = urlParams.get('timezone');

if (tzOverride) {
dateInTz = date.setZone(tzOverride.replace(' ', '+'));
} else if (timezone) {
dateInTz = date.setZone(timezone);
}

if (!dateInTz.isValid) {
return (
<>
<span className="date_weekday">Incorrect Timezone</span>
</>
);
}

return (
<>
<span className="date_weekday">{`${dateInTz.toFormat('EEEE')}, `}</span>
Expand Down
31 changes: 31 additions & 0 deletions test/acceptance/oncall-P538IZH-custom-timezone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ------- Imports -------------------------------------------------------------

import test from 'ava';
import chai from 'chai';

// ------- Internal imports ----------------------------------------------------

import { AcceptanceHelpers } from '../helpers/AcceptanceHelpers';

// ------- Init ----------------------------------------------------------------

const { expect } = chai;
const { waitFor } = AcceptanceHelpers;

test.before(AcceptanceHelpers.openBrowser);
test.serial.before(AcceptanceHelpers.openPage('/v1/schedules/P538IZH.html?timezone=UTC+2'));
test.after.always(AcceptanceHelpers.closeBrowser);

// ------- Tests ---------------------------------------------------------------

test('On-Call P538IZH: Check page response', (t) => {
expect(t.context.pageResponse.ok()).to.be.true;
});

test('On-Call P538IZH: status row shows dates in custom timezone', waitFor('.schedule'), async (t) => {
const { pageTest } = t.context;
await pageTest.expectText('.date_start', 'From: Tuesday, Dec 25 7:00 AM');
await pageTest.expectText('.date_end', 'To: Tuesday, Dec 25 7:00 PM');
});

// ------- End -----------------------------------------------------------------
2 changes: 1 addition & 1 deletion test/acceptance/oncall-PJ1P5JQ-no-end-date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('On-Call PJ1P5JQ: show user avatar', waitFor('.schedule'), async (t) => {

test('On-Call PJ1P5JQ: no end date in status row', waitFor('.schedule'), async (t) => {
const { pageTest } = t.context;
await pageTest.expectText('.date_start', 'From: Tuesday, Dec 25 12:00 AM');
await pageTest.expectText('.date_start', 'From: Monday, Dec 24 9:00 PM');
await pageTest.expectNoElements('.date_end');
});

Expand Down
2 changes: 1 addition & 1 deletion test/mocks/schedules/PJ1P5JQ/GET.mock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Cache-Control: max-age=0, private, must-revalidate
"self": "https://api.pagerduty.com/schedules/PJ1P5JQ",
"html_url": "https://apidocs.pagerduty.com/schedules/PJ1P5JQ",
"name": "Schedule aliquid eum qui",
"time_zone": "America/New_York",
"time_zone": "America/Los_Angeles",
"description": null,
"users": [
{
Expand Down