*At least it's the default in Postgres. Other databases may differ.
A little background on timezones
For Portland, it can be:
Timezone is a product of location, date, and time
const googleMapsClient = require('@google/maps').createClient({
key: process.env.GOOGLE_API_KEY,
Promise: Promise
});
module.exports = async (req, res, next) => {
try {
const address = `${req.body.streetAddress} ${req.body.streetAddress2 || ''} ${req.body.city}, ${req.body.state} ${req.body.zipCode}`;
const geocodedAddress = await googleMapsClient.geocode({ address }).asPromise();
if (geocodedAddress) {
const coordinates = geocodedAddress.json.results[0].geometry.location;
req.body.location = {
type: 'Point',
coordinates: [
coordinates.lat,
coordinates.lng
],
crs: {
type: 'name',
properties: {
name: 'EPSG:4326'
}
}
};
}
return next();
}
catch(err) {
next(err);
}
};
const googleMapsClient = require('@google/maps').createClient({
key: process.env.GOOGLE_API_KEY,
Promise: Promise
});
module.exports = async (req, res, next) => {
try {
const location = req.body.location.coordinates;
const language = 'en';
const timezoneName = await googleMapsClient.timezone({ location, language }).asPromise();
if (timezoneName.json) {
req.body.timezone = timezoneName.json.timeZoneId;
}
return next();
}
catch(err) {
next(err);
}
};
// wherever you put your routes
const geocode = require('../path/to/middleware/geocode');
const timezone = require('../path/to/middleware/timezone');
app.post('/api/locations/', [geocode, timezone], createLocation);
// wherever you put your controllers
const { Location } = require('../path/to/models');
async function createLocation(req, res) {
try {
const location = await Location.create(req.body);
res.status(201).json(location);
}
catch(err) {
console.log(err);
}
}
<!-- Input for selecting date -->
<div kcd-recompile="$ctrl.event.timezoneOffset">
<md-input-container class="md-block">
<label>Date</label>
<input
type="text"
mdc-datetime-picker
ng-model="$ctrl.event.datetime"
ng-model-options="{ timezone: $ctrl.event.timezoneOffset }"
date="true"
time="true"
short-time="true"
format="MMM D, YYYY h:mm a Z">
</md-input-container>
</div>
<!-- Filtering date for output -->
<p>{{ $ctrl.event.datetime.toISOString() | date:"EEEE, MMMM d, y 'at' h:mma":$ctrl.event.timezoneOffset }}</p>
ctrl.setTimezoneOffset = function() {
var datetime = ctrl.event.datetime;
var timezoneName = ctrl.locations.find(function(location) {
return location.id === ctrl.event.LocationId;
}).timezone;
ctrl.event.timezoneOffset = moment(datetime).tz(timezoneName).format('ZZ');
// convert the datetime to the new timezone, if one's been chosen
if (datetime) {
ctrl.event.datetime = moment(datetime).tz(timezoneName);
}
};