Skip to content

Commit 84a6845

Browse files
bricedKyleAMathews
authored andcommitted
Added support for a custom locale when querying a date (#2382)
1 parent 855ad0c commit 84a6845

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/gatsby/src/schema/infer-graphql-type.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,20 @@ function inferGraphQLType({
128128
and seconds.`,
129129
},
130130
},
131-
resolve(object, { fromNow, difference, formatString }) {
131+
resolve(object, { fromNow, difference, formatString, locale = `en` }) {
132132
let date
133133
if (object[fieldName]) {
134134
date = JSON.parse(JSON.stringify(object[fieldName]))
135135
} else {
136136
return null
137137
}
138138
if (formatString) {
139-
return moment.utc(date, ISO_8601_FORMAT, true).format(formatString)
139+
return moment.utc(date, ISO_8601_FORMAT, true).locale(locale).format(formatString)
140140
} else if (fromNow) {
141-
return moment.utc(date, ISO_8601_FORMAT, true).fromNow()
141+
return moment.utc(date, ISO_8601_FORMAT, true).locale(locale).fromNow()
142142
} else if (difference) {
143143
return moment().diff(
144-
moment.utc(date, ISO_8601_FORMAT, true),
144+
moment.utc(date, ISO_8601_FORMAT, true).locale(locale),
145145
difference
146146
)
147147
} else {

0 commit comments

Comments
 (0)