Convert times to Mountain time instead of user's timezone

This commit is contained in:
Tanner Collin 2020-02-24 04:07:18 +00:00
parent 9de7368174
commit b4b94c277f
6 changed files with 22 additions and 14 deletions

View File

@ -7,6 +7,7 @@
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"moment": "^2.24.0",
"moment-timezone": "^0.5.28",
"react": "^16.12.0",
"react-datetime": "^2.16.3",
"react-dom": "^16.12.0",

View File

@ -2,7 +2,7 @@ import React, { useState, useEffect, useReducer } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
import './light.css';
import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment';
import moment from 'moment-timezone';
import { isAdmin, isInstructor, BasicTable, requester } from './utils.js';
import { NotFound, PleaseLogin } from './Misc.js';
import { InstructorClassDetail, InstructorClassAttendance } from './InstructorClasses.js';
@ -31,10 +31,10 @@ function ClassTable(props) {
<Table.Cell>{x.course_name}</Table.Cell>
<Table.Cell>
<Link to={'/classes/'+x.id}>
{moment.utc(x.datetime).local().format('ll')}
{moment.utc(x.datetime).tz('America/Edmonton').format('ll')}
</Link>
</Table.Cell>
<Table.Cell>{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).local().format('LT')}</Table.Cell>
<Table.Cell>{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).tz('America/Edmonton').format('LT')}</Table.Cell>
<Table.Cell>{x.instructor_name}</Table.Cell>
<Table.Cell>{x.cost === '0.00' ? 'Free' : '$'+x.cost}</Table.Cell>
<Table.Cell>{x.student_count} {!!x.max_students && '/ '+x.max_students}</Table.Cell>
@ -160,13 +160,13 @@ export function ClassDetail(props) {
<Table.Row>
<Table.Cell>Date:</Table.Cell>
<Table.Cell>
{moment.utc(clazz.datetime).local().format('ll')}
{moment.utc(clazz.datetime).tz('America/Edmonton').format('ll')}
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Time:</Table.Cell>
<Table.Cell>
{clazz.is_cancelled ? 'Cancelled' : moment.utc(clazz.datetime).local().format('LT')}
{clazz.is_cancelled ? 'Cancelled' : moment.utc(clazz.datetime).tz('America/Edmonton').format('LT')}
</Table.Cell>
</Table.Row>
<Table.Row>

View File

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
import './light.css';
import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment';
import moment from 'moment-timezone';
import { isInstructor, requester } from './utils.js';
import { NotFound, PleaseLogin } from './Misc.js';
import { InstructorCourseList, InstructorCourseDetail } from './InstructorCourses.js';
@ -122,10 +122,10 @@ export function CourseDetail(props) {
<Table.Row key={x.id}>
<Table.Cell>
<Link to={'/classes/'+x.id}>
{moment.utc(x.datetime).local().format('ll')}
{moment.utc(x.datetime).tz('America/Edmonton').format('ll')}
</Link>
</Table.Cell>
<Table.Cell>{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).local().format('LT')}</Table.Cell>
<Table.Cell>{x.is_cancelled ? 'Cancelled' : moment.utc(x.datetime).tz('America/Edmonton').format('LT')}</Table.Cell>
<Table.Cell>{x.instructor_name}</Table.Cell>
<Table.Cell>{x.cost === '0.00' ? 'Free' : '$'+x.cost}</Table.Cell>
</Table.Row>

View File

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
import moment from 'moment';
import moment from 'moment-timezone';
import './light.css';
import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { statusColor, BasicTable, staticUrl, requester } from './utils.js';
@ -141,7 +141,7 @@ export function Home(props) {
}, []);
const getStat = (x) => stats && stats[x] ? stats[x] : '?';
const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).local().format('ll') : '?';
const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).tz('America/Edmonton').format('ll') : '?';
return (
<Container>

View File

@ -3,7 +3,7 @@ import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } f
import ReactToPrint from 'react-to-print';
import * as Datetime from 'react-datetime';
import 'react-datetime/css/react-datetime.css';
import moment from 'moment';
import moment from 'moment-timezone';
import './light.css';
import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Label, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { BasicTable, staticUrl, requester } from './utils.js';
@ -18,7 +18,7 @@ class AttendanceSheet extends React.Component {
<div style={{ padding: '3rem' }}>
<Header size='medium'>{clazz.course_name} Attendance</Header>
<p>
{moment.utc(clazz.datetime).local().format('llll')}
{moment.utc(clazz.datetime).tz('America/Edmonton').format('llll')}
{num >= 2 ? ', '+num+' students sorted by registration time.' : '.'}
</p>
@ -241,7 +241,7 @@ function InstructorClassEditor(props) {
<label>Time and Date</label>
<Datetime
timeConstraints={{ minutes: { step: 15 } }}
value={ input.datetime ? moment.utc(input.datetime).local() : (new Date()).setMinutes(0) }
value={ input.datetime ? moment.utc(input.datetime).tz('America/Edmonton') : (new Date()).setMinutes(0) }
onChange={handleDatetime}
/>
{error.datetime &&

View File

@ -6682,7 +6682,14 @@ mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
dependencies:
minimist "0.0.8"
moment@^2.24.0:
moment-timezone@^0.5.28:
version "0.5.28"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.28.tgz#f093d789d091ed7b055d82aa81a82467f72e4338"
integrity sha512-TDJkZvAyKIVWg5EtVqRzU97w0Rb0YVbfpqyjgu6GwXCAohVRqwZjf4fOzDE6p1Ch98Sro/8hQQi65WDXW5STPw==
dependencies:
moment ">= 2.9.0"
"moment@>= 2.9.0", moment@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==