Skip to content

Commit

Permalink
fix date field in sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyler1d committed Jan 24, 2020
1 parent 05ebfe9 commit c4cbf3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/MessageList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MessageList = function MessageList(props) {
style={message.isFromContact ? styles.received : styles.sent}
key={message.id}
primaryText={message.text}
secondaryText={moment(message.createdAt).fromNow()}
secondaryText={moment.utc(message.createdAt).fromNow()}
/>
))}
{optOutItem}
Expand Down
8 changes: 7 additions & 1 deletion src/server/api/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ export function mapFieldsToModel(fields, model) {
const snakeKey = humps.decamelize(field, { separator: "_" });
// eslint-disable-next-line no-underscore-dangle
if (model._schema._schema.hasOwnProperty(snakeKey)) {
resolvers[field] = instance => instance[snakeKey];
if (/At$/.test(field)) {
// force a Date-type: esp. important for sqlite
resolvers[field] = instance =>
instance[snakeKey] ? new Date(instance[snakeKey]) : null;
} else {
resolvers[field] = instance => instance[snakeKey];
}
} else {
// eslint-disable-next-line no-underscore-dangle
throw new Error(
Expand Down

0 comments on commit c4cbf3c

Please sign in to comment.