Skip to content

Commit

Permalink
wip: time
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Oct 10, 2023
1 parent 258556a commit f167afe
Showing 1 changed file with 59 additions and 63 deletions.
122 changes: 59 additions & 63 deletions app/qml/editor/inputdatetime.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,82 +34,90 @@ AbstractEditor {

enabled: !isReadOnly

function timeToString(attrValue) {
if (attrValue === undefined)
{
return ''
}
else
{
return Qt.formatDateTime(attrValue, config['display_format'])
QtObject {
id: dateTransformer

function toJsDate(qtDate) {
if ( root.parentField.isDateOrTime ) {
if (root.fieldIsDate) {
// if the field is a QDate (3 ints ==> Year, Month, Day, no timezone),
// during the automatic conversion to JS date [1] it is assumed that QDate
// is in UTC timezone. Therefore if 2001-01-01 is stored in date file,
// it will become 2000-12-31 19:00:00 -05 in QML/JS in UTC -05 zone.
// However, we the correct conversion is 2001-01-01 00:00:00 -05.
// [1] http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#basic-qt-data-types

let date = new Date(qtDate.getUTCFullYear(), qtDate.getUTCMonth(), qtDate.getUTCDate() )
console.log("toJsDate", qtDate, date)
return date
}
else {
return qtDate
}
}
else {
return Date.fromLocaleString(Qt.locale(), qtDate, config['field_format'])
}
}
}

function formatText(v) {
if ( v === undefined || root.parentValueIsNull )
{
return ''
}
else
{
if ( root.parentField.isDateOrTime )
{
// if the field is a QDate, the automatic conversion to JS date [1]
// leads to the creation of date time object with the time zone.
// For instance shapefiles has support for dates but not date/time or time.
// So a date coming from a shapefile as 2001-01-01 will become 2000-12-31 19:00:00 -05 in QML/JS in UTC -05 zone.
// And when formatting this with the display format, this is shown as 2000-12-31.
// So we detect if the field is a date only and revert the time zone offset.
// [1] http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#basic-qt-data-types
if (root.fieldIsDate)
{
return Qt.formatDateTime( new Date(v.getTime() + v.getTimezoneOffset() * 60000), config['display_format'])
}
else
function toQtDate(jsDate) {
if ( root.parentField.isDateOrTime ) {
if (root.fieldIsDate) {
// For QDate, the year, month and day is clipped based on
// the local timezone in QgsFeature.convertCompatible
return jsDate.toISOString()
} else
{
return Qt.formatDateTime(v, config['display_format'])
return jsDate
}
}
else
{
let date = Date.fromLocaleString(Qt.locale(), v, config['field_format'])
return Qt.formatDateTime(date, config['display_format'])
else {
return jsDate.toLocaleString(Qt.locale(), config['field_format'])
}
}
}

function openPicker(requestedDate)
{
// open calendar for today when no date is set
if (!requestedDate)
requestedDate = new Date()
function newDateSelected( jsDate ) {
if ( jsDate ) {
let qtDate = dateTransformer.toQtDate(jsDate)
root.editorValueChanged(qtDate, false)
}
}

function formatText( qtDate ) {
if ( qtDate === undefined || root.parentValueIsNull ) {
return ''
}
else {
let jsDate = dateTransformer.toJsDate(qtDate)
return Qt.formatDateTime(jsDate, config['display_format'])
}
}

function openPicker(requestedDate) {
dateTimeDrawerLoader.active = true
dateTimeDrawerLoader.focus = true
dateTimeDrawerLoader.item.dateToOpen = requestedDate
}

onContentClicked: {
if (root.parentValueIsNull)
{
root.openPicker()
if (root.parentValueIsNull) {
// open calendar for today when no date is set
root.openPicker( new Date() )
}
else
{
root.openPicker(root.parentValue)
else {
root.openPicker( dateTransformer.toJsDate(root.parentValue) )
}
}

onRightActionClicked: {
let newDate = new Date()
let newValue = field.isDateOrTime ? newDate : Qt.formatDateTime(newDate, config['field_format'])
editorValueChanged(newValue, false)
root.newDateSelected( new Date() )
}

content: Text {
id: dateText

text: formatText(root.parentValue)
text: formatText( root.parentValue )

anchors.fill: parent

Expand Down Expand Up @@ -194,19 +202,7 @@ AbstractEditor {
hasTimePicker: root.includesTime

onSelected: function( selectedDate ) {
if ( selectedDate )
{
if ( root.parentField.isDateOrTime )
{
root.editorValueChanged(selectedDate, false)
}
else
{
let dateStr = selectedDate.toLocaleString(Qt.locale(), config['field_format'])
root.editorValueChanged(dateStr, false)
}
}

root.newDateSelected( selectedDate )
dateTimeDrawer.close()
}

Expand Down

1 comment on commit f167afe

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.10.466711 just submitted!

Please sign in to comment.