Skip to content

Commit 8c0a855

Browse files
committed
international timezones and timezones
1 parent 0e5cbb9 commit 8c0a855

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

src/components/appointments/Appointments.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const Apt = ({apt, props, appointment_attendees}) => {
2727
return (
2828
<Link to={props.root.url(`appointment/${apt.link}`)} className="tcs-item">
2929
<div className={`tcs-apt ${colour_contrast(apt.service_colour)}`} style={{background: apt.service_colour}}>
30-
<div style={{fontWeight: 700, marginRight: 10}}>
31-
{props.config.date_fns.format(apt.start, 'HH:mm')}
30+
<div style={{fontWeight: 700, marginRight: 8, minWidth: 68}}>
31+
{props.config.format_dt(apt.start, 'time')}
3232
</div>
3333
<div className="tcs-truncate">
3434
{apt.topic}<Bull/>{apt.service_name}
@@ -52,8 +52,8 @@ const AptDayGroup = ({appointments, props, appointment_attendees}) => {
5252
return (
5353
<div className="tcs-apt-group-day">
5454
<div className="tcs-day">
55-
{props.config.date_fns.format(first_apt.start, 'ddd')}
56-
<div className="tcs-day-no">{props.config.date_fns.format(first_apt.start, 'd')}</div>
55+
{props.config.format_dt(first_apt.start, 'weekday')}
56+
<div className="tcs-day-no">{props.config.format_dt(first_apt.start, 'day')}</div>
5757
</div>
5858
<div>
5959
{appointments.map(apt => (
@@ -167,7 +167,7 @@ class Appointments extends Component {
167167
<div className="tcs-app tcs-appointments">
168168
{months.map(({date, appointments}, i) => (
169169
<div className="tcs-apt-group-month" key={i}>
170-
<div className="tcs-title">{this.props.config.date_fns.format(date, 'MMMM')}</div>
170+
<div className="tcs-title">{this.props.config.format_dt(date, 'month')}</div>
171171
{appointments.map((appointments, j) => (
172172
<AptDayGroup key={j} appointments={appointments} props={this.props}
173173
appointment_attendees={this.state.appointment_attendees}/>

src/components/appointments/AptModal.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React, { Component } from 'react'
2-
import {If, IfElse, DisplayExtraAttrs} from '../shared/Tools'
2+
import {Bull, If, IfElse, DisplayExtraAttrs} from '../shared/Tools'
33
import {Tick, CalendarPlus, CalendarTimes} from '../shared/Svgs'
44
import Modal from '../shared/Modal'
55

66
const get_attendees = (appointment_attendees, apt_id) => (appointment_attendees && appointment_attendees[apt_id]) || []
77
const NEW_STUDENT_ID = 999999999
8-
const DATE_FMT = 'MMM Do h:m a'
98

109

1110
const AptDetails = ({apt, spaces_available, attending, props}) => {
1211
const c = props.config
1312
const CalendarIcon = spaces_available ? CalendarPlus : CalendarTimes
1413
return (
1514
<div>
15+
<div className="tcs-right tcs-timezone">
16+
{props.config.get_text('assuming_timezone', {timezone: props.config.timezone})}
17+
</div>
1618
<div className={`tcs-apt-details ${spaces_available ? 'tcs-bookable' : ''}`}>
1719
<div>
1820
<CalendarIcon/>
@@ -25,10 +27,10 @@ const AptDetails = ({apt, spaces_available, attending, props}) => {
2527
</div>
2628
<IfElse v={apt.start.substr(0, 10) === apt.finish.substr(0, 10)}>
2729
<div>
28-
{c.date_fns.format(apt.start, DATE_FMT)} &bull; {c.format_duration(apt.finish, apt.start)}
30+
{c.format_dt(apt.start, 'full')}<Bull/>{c.format_duration(apt.finish, apt.start)}
2931
</div>
3032
<div>
31-
{c.date_fns.format(apt.start, DATE_FMT)} - {c.date_fns.format(apt.finish, DATE_FMT)}
33+
{c.format_dt(apt.start, 'full')} - {c.format_dt(apt.finish, 'full')}
3234
</div>
3335
</IfElse>
3436
</div>
@@ -179,7 +181,7 @@ class AptModal extends Component {
179181
const title = (
180182
<span>
181183
<span className="tcs-circle" style={{background: apt.service_colour}}/>
182-
{apt.topic} &bull; {apt.service_name}
184+
{apt.topic} <Bull/> {apt.service_name}
183185
</span>
184186
)
185187
const students = this.get_students()

src/formatting.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,27 @@ export function format_money (amount) {
2121
}
2222
}
2323

24-
export function format_date (ts) {
25-
return this.date_fns.format(new Date(ts), this.format.date)
24+
const intl_options = Intl.DateTimeFormat().resolvedOptions()
25+
const locale = intl_options.locale || 'en-US'
26+
export const timezone = intl_options.timeZone || 'utc'
27+
// const LOCALE = 'en-US'
28+
const FORMAT_OPTIONS = {
29+
full: {day: 'numeric', month: 'long', hour: 'numeric', minute: 'numeric'},
30+
month: {month: 'short'},
31+
day: {day: 'numeric'},
32+
weekday: {weekday: 'short'},
33+
time: {hour: 'numeric', minute: 'numeric'}
34+
}
35+
36+
export function format_dt (ts, fmt) {
37+
// timestampts are alwasy in utc thus we need to add the 0000 and js will take care of the rest
38+
const d = new Date(ts + '+0000')
39+
let options = FORMAT_OPTIONS[fmt]
40+
if (!options) {
41+
console.warn('unknown date format:', fmt)
42+
43+
}
44+
return Intl.DateTimeFormat(locale, options).format(d)
2645
}
2746

2847
export function format_duration (ts1, ts2) {

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import Raven from 'raven-js'
22
import React from 'react'
33
import ReactDOM from 'react-dom'
44
import 'babel-polyfill'
5-
import format from 'date-fns/format'
65
import './main.scss'
76
import App from './components/App'
87
import {BrowserRouter, HashRouter} from 'react-router-dom'
98
import {auto_url_root, get_company_options} from './utils'
10-
import {format_money, format_duration, get_text} from './formatting'
9+
import {format_money, format_dt, format_duration, get_text, timezone} from './formatting'
1110

1211
const raven_config = {
1312
release: process.env.REACT_APP_RELEASE,
@@ -73,6 +72,7 @@ const STRINGS = {
7372
location: 'Location',
7473
not_you_sign_out: 'Not you? sign out',
7574
added: 'Added',
75+
assuming_timezone: '(Times assume your timezone is {timezone})'
7676
}
7777

7878
const MODES = ['grid', 'list', 'enquiry', 'enquiry-modal', 'appointments']
@@ -150,7 +150,8 @@ window.socket = async function (public_key, config) {
150150
datetime: 'HH:mm DD/MM/YYYY',
151151
date: 'DD/MM/YYYY'
152152
}
153-
config.date_fns = {format}
153+
config.timezone = config.timezone || timezone
154+
config.format_dt = (config.format_dt || format_dt).bind(config)
154155
config.format_duration = (config.format_duration || format_duration).bind(config)
155156
config.format_money = (config.format_money || format_money).bind(config)
156157

src/styles/appointments.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ $colour-positive: #83aa68;
9090
}
9191
}
9292

93+
.tcs-timezone {
94+
font-size: 13px;
95+
color: #444;
96+
margin-bottom: 5px;
97+
}
9398

9499
.tcs-signout {
95100
color: $brand-colour;

0 commit comments

Comments
 (0)