Skip to content

Commit

Permalink
Merge pull request #844 from dadi/develop
Browse files Browse the repository at this point in the history
Datetime picker fixes
  • Loading branch information
feroviktor authored Apr 21, 2021
2 parents 20fa508 + 5cf0e25 commit 8791a56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ export default class TextInputWithDatePicker extends React.Component {
handleInputChange(event) {
const {format, onChange} = this.props
const {value} = event.target
const newDate = new DateTime(event.target.value, format)
const newDate = new DateTime(
event.target.value,
format === 'unix' ? 'YYYY/MM/DD HH:mm' : format
)

if (value.length === format.length && newDate.isValid()) {
if (
(format === 'unix' || value.length === format.length) &&
newDate.isValid()
) {
if (typeof onChange === 'function') {
const utcDate = newDate.getDate({toUTC: true})

Expand Down Expand Up @@ -219,6 +225,7 @@ export default class TextInputWithDatePicker extends React.Component {
containerClassName
)
const showTimePicker =
format === 'unix' ||
typeof format !== 'string' ||
format.includes('HH') ||
format.includes('mm')
Expand Down
10 changes: 6 additions & 4 deletions app/lib/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export default class DateTime {
}

format(format, convertToUTC = true) {
// convertToUTC - this param doesn't seem to be ever used in the code... so always defaults to true
let output = null

try {
const date = convertToUTC
? this._getUTCDateFromLocalDate(this.localDate)
: this.localDate
const date = this.localDate

if (format === 'unix') {
output =
Expand All @@ -85,7 +84,10 @@ export default class DateTime {
return output
}

getDate() {
getDate(options ={toUTC:false}) {
if(options.toUTC){
return this._getUTCDateFromLocalDate(this.localDate)
}
return this.localDate
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dadi/publish",
"version": "3.0.2",
"version": "3.0.3",
"description": "DADI Publish",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8791a56

Please sign in to comment.