-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Template] adds date timezone and format in options
- Loading branch information
Showing
31 changed files
with
586 additions
and
569 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/app/Resources/modules/data/types/timezone/components/input.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
|
||
import {constants} from '#/main/app/intl/date/constants' | ||
|
||
import {PropTypes as T, implementPropTypes} from '#/main/app/prop-types' | ||
import {DataInput as DataInputTypes} from '#/main/app/data/types/prop-types' | ||
import {Select} from '#/main/app/input/components/select' | ||
|
||
const TimezoneInput = props => | ||
<Select | ||
{...props} | ||
choices={constants.TIMEZONES} | ||
/> | ||
|
||
implementPropTypes(TimezoneInput, DataInputTypes, { | ||
value: T.string, | ||
noEmpty: T.bool | ||
}, { | ||
value: '' | ||
}) | ||
|
||
export { | ||
TimezoneInput | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/app/Resources/modules/data/types/timezone/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {trans, tval} from '#/main/app/intl/translation' | ||
import {chain, string} from '#/main/app/data/types/validators' | ||
|
||
import {constants} from '#/main/app/intl/date/constants' | ||
import {TimezoneInput} from '#/main/app/data/types/timezone/components/input' | ||
|
||
const dataType = { | ||
name: 'timezone', | ||
meta: { | ||
icon: 'fa fa-fw fa-clock', | ||
label: trans('timezone', {}, 'data'), | ||
description: trans('timezone_desc', {}, 'data'), | ||
creatable: false | ||
}, | ||
|
||
/** | ||
* Translates timezone code for display. | ||
*/ | ||
render: (raw) => { | ||
if (raw) { | ||
return trans(raw, {}, 'timezones') | ||
} | ||
|
||
return null | ||
}, | ||
|
||
validate: (value, options) => chain(value, options, [string, (timezone) => { | ||
if (!constants.TIMEZONE_CODES.includes(timezone)) { | ||
return tval('This value should be a valid timezone.') | ||
} | ||
}]), | ||
|
||
components: { | ||
input: TimezoneInput | ||
} | ||
} | ||
|
||
export { | ||
dataType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
import {constants as langConst} from '#/main/app/intl/lang/constants' | ||
import {constants as dateConst} from '#/main/app/intl/date/constants' | ||
import {constants as regionConst} from '#/main/app/intl/region/constants' | ||
|
||
export const constants = Object.assign({}, | ||
langConst, | ||
dateConst, | ||
regionConst | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import {trans} from '#/main/app/intl/translation' | ||
|
||
const TIMEZONE_CODES = [ | ||
'Pacific/Midway', | ||
'US/Samoa', | ||
'US/Hawaii', | ||
'US/Alaska', | ||
'US/Pacific', | ||
'America/Tijuana', | ||
'US/Arizona', | ||
'US/Mountain', | ||
'America/Chihuahua', | ||
'America/Mazatlan', | ||
'America/Mexico_City', | ||
'America/Monterrey', | ||
'Canada/Saskatchewan', | ||
'US/Central', | ||
'US/Eastern', | ||
'US/East-Indiana', | ||
'America/Bogota', | ||
'America/Lima', | ||
'America/Caracas', | ||
'Canada/Atlantic', | ||
'America/La_Paz', | ||
'America/Santiago', | ||
'Canada/Newfoundland', | ||
'America/Buenos_Aires', | ||
'Greenland', | ||
'Atlantic/Stanley', | ||
'Atlantic/Azores', | ||
'Atlantic/Cape_Verde', | ||
'Africa/Casablanca', | ||
'Europe/Dublin', | ||
'Europe/Lisbon', | ||
'Europe/London', | ||
'Africa/Monrovia', | ||
'Europe/Amsterdam', | ||
'Europe/Belgrade', | ||
'Europe/Berlin', | ||
'Europe/Bratislava', | ||
'Europe/Brussels', | ||
'Europe/Budapest', | ||
'Europe/Copenhagen', | ||
'Europe/Ljubljana', | ||
'Europe/Madrid', | ||
'Europe/Paris', | ||
'Europe/Prague', | ||
'Europe/Rome', | ||
'Europe/Sarajevo', | ||
'Europe/Skopje', | ||
'Europe/Stockholm', | ||
'Europe/Vienna', | ||
'Europe/Warsaw', | ||
'Europe/Zagreb', | ||
'Europe/Athens', | ||
'Europe/Bucharest', | ||
'Africa/Cairo', | ||
'Africa/Harare', | ||
'Europe/Helsinki', | ||
'Europe/Istanbul', | ||
'Asia/Jerusalem', | ||
'Europe/Kiev', | ||
'Europe/Minsk', | ||
'Europe/Riga', | ||
'Europe/Sofia', | ||
'Europe/Tallinn', | ||
'Europe/Vilnius', | ||
'Asia/Baghdad', | ||
'Asia/Kuwait', | ||
'Africa/Nairobi', | ||
'Asia/Riyadh', | ||
'Europe/Moscow', | ||
'Asia/Tehran', | ||
'Asia/Baku', | ||
'Europe/Volgograd', | ||
'Asia/Muscat', | ||
'Asia/Tbilisi', | ||
'Asia/Yerevan', | ||
'Asia/Kabul', | ||
'Asia/Karachi', | ||
'Asia/Tashkent', | ||
'Asia/Kolkata', | ||
'Asia/Kathmandu', | ||
'Asia/Yekaterinburg', | ||
'Asia/Almaty', | ||
'Asia/Dhaka', | ||
'Asia/Novosibirsk', | ||
'Asia/Bangkok', | ||
'Asia/Jakarta', | ||
'Asia/Krasnoyarsk', | ||
'Asia/Chongqing', | ||
'Asia/Hong_Kong', | ||
'Asia/Kuala_Lumpur', | ||
'Australia/Perth', | ||
'Asia/Singapore', | ||
'Asia/Taipei', | ||
'Asia/Ulaanbaatar', | ||
'Asia/Urumqi', | ||
'Asia/Irkutsk', | ||
'Asia/Seoul', | ||
'Asia/Tokyo', | ||
'Australia/Adelaide', | ||
'Australia/Darwin', | ||
'Asia/Yakutsk', | ||
'Australia/Brisbane', | ||
'Australia/Canberra', | ||
'Pacific/Guam', | ||
'Australia/Hobart', | ||
'Australia/Melbourne', | ||
'Pacific/Port_Moresby', | ||
'Australia/Sydney', | ||
'Asia/Vladivostok', | ||
'Asia/Magadan', | ||
'Pacific/Auckland', | ||
'Pacific/Fiji' | ||
] | ||
|
||
/** | ||
* The list of world timezones with translated names. | ||
* Can be used in a <Select /> | ||
* | ||
* @type {object} | ||
*/ | ||
const TIMEZONES = TIMEZONE_CODES | ||
.reduce((timezones, timezoneCode) => Object.assign(timezones,{ | ||
[timezoneCode]: trans(timezoneCode, {}, 'timezones') | ||
}), {}) | ||
|
||
export const constants = { | ||
TIMEZONE_CODES, | ||
TIMEZONES | ||
} |
Oops, something went wrong.