@@ -18,6 +18,7 @@ import {
1818 AdvancedToggleControl ,
1919 useBlockCssGenerator ,
2020 ControlSeparator ,
21+ AdvancedSelectControl ,
2122} from '~stackable/components'
2223import {
2324 BlockDiv ,
@@ -39,6 +40,8 @@ import {
3940 withQueryLoopContext ,
4041} from '~stackable/higher-order'
4142
43+ import { timezones as TIMEZONE_OPTIONS } from '../countdown'
44+
4245/**
4346 * WordPress dependencies
4447 */
@@ -47,7 +50,8 @@ import { InnerBlocks } from '@wordpress/block-editor'
4750import { __ } from '@wordpress/i18n'
4851import { addFilter } from '@wordpress/hooks'
4952import { memo } from '@wordpress/element'
50- import { DatePicker } from '@wordpress/components'
53+ import { DateTimePicker } from '@wordpress/components'
54+ import { getSettings as getDateSettings } from '@wordpress/date'
5155
5256export const defaultIcon = '<svg data-prefix="fas" data-icon="play" class="svg-inline--fa fa-play fa-w-14" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" aria-hidden="true"><path fill="currentColor" d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"></path></svg>'
5357
@@ -109,6 +113,7 @@ const Edit = props => {
109113 videoName = { attributes . videoName }
110114 videoUploadDate = { attributes . videoUploadDate }
111115 videoDescription = { attributes . videoDescription }
116+ videoUploadDateTimezone = { attributes . videoUploadDateTimezone }
112117 />
113118
114119 { blockCss && < style key = "block-css" > { blockCss } </ style > }
@@ -133,6 +138,28 @@ const Edit = props => {
133138}
134139
135140const InspectorControls = memo ( props => {
141+ const getUploadDate = ( uploadDate , timezone ) => {
142+ // If it uses local timezone, get offset from WordPress settings
143+ if ( ! timezone ) {
144+ const { timezone : localTimezone } = getDateSettings ( )
145+ const offset = Number ( localTimezone . offset )
146+ const hours = Math . floor ( Math . abs ( offset ) )
147+ const minutes = Math . round ( ( Math . abs ( offset ) % 1 ) * 60 )
148+
149+ return uploadDate + ( offset >= 0 ? '+' : '-' ) +
150+ String ( hours ) . padStart ( 2 , '0' ) + ':' +
151+ String ( minutes ) . padStart ( 2 , '0' )
152+ }
153+
154+ const date = new Date ( uploadDate )
155+ const offset = new Intl . DateTimeFormat ( 'en-US' , {
156+ timeZone : timezone ,
157+ timeZoneName : 'longOffset' ,
158+ } ) . format ( date ) . slice ( - 6 )
159+
160+ return uploadDate + offset
161+ }
162+
136163 return (
137164 < >
138165 < InspectorTabs hasLayoutPanel = { false } />
@@ -221,15 +248,21 @@ const InspectorControls = memo( props => {
221248 // This text control allows users to see if a date has been set/removed
222249 className = "stk-components-datetime__date-input"
223250 label = { __ ( 'Video upload date' , i18n ) }
224- value = { props . videoUploadDate ? new Date ( props . videoUploadDate ) . toISOString ( ) . slice ( 0 , 10 ) : '' }
251+ value = { props . videoUploadDate ? getUploadDate ( props . videoUploadDate , props . videoUploadDateTimezone ) : '' }
252+ onChange = { videoUploadDate => props . setAttributes ( { videoUploadDate } ) }
225253 inputType = "date"
226254 readOnly = { true }
227255 />
228- < DatePicker
256+ < DateTimePicker
229257 currentDate = { props . videoUploadDate }
230- onChange = { videoUploadDate => {
231- props . setAttributes ( { videoUploadDate } )
232- } }
258+ is12Hour = { true }
259+ onChange = { videoUploadDate => props . setAttributes ( { videoUploadDate } ) }
260+ />
261+ < AdvancedSelectControl
262+ label = { __ ( 'Timezone' , i18n ) }
263+ options = { TIMEZONE_OPTIONS }
264+ attribute = "videoUploadDateTimezone"
265+ allowReset = { false }
233266 />
234267 </ > }
235268
0 commit comments