Skip to content

Commit

Permalink
fix: timezone adjustment for date type
Browse files Browse the repository at this point in the history
  • Loading branch information
deejay-hub committed Dec 1, 2023
1 parent 6ee8d4b commit 8ad3407
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions force-app/main/default/classes/TimelineService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ public with sharing class TimelineService {
mapData.put('detailFieldLabel', detailValues.get('label'));
mapData.put('positionDateField', positionValues.get('label'));
mapData.put('positionDateValue', positionValues.get('value'));
mapData.put('positionDateType', positionValues.get('type'));
mapData.put('objectName', tr.objectName);
mapData.put('fallbackTooltipField', fallbackValues.get('label'));
mapData.put('fallbackTooltipValue', fallbackValues.get('value'));
Expand Down Expand Up @@ -421,6 +422,7 @@ public with sharing class TimelineService {

String fieldValue = '';
String fieldLabel = '';
String fieldType = '';
String objectCheck = '';
//String fieldCheck = '';
String fieldStripped = '';
Expand Down Expand Up @@ -512,6 +514,7 @@ public with sharing class TimelineService {

fieldLabel = fieldMetadata.getLabel();
fieldCanAccess = fieldMetadata.isAccessible();
fieldType = String.valueOf(fieldMetadata.getType());

if (fieldCanAccess == false) {
fieldValue = '![' + fieldLabel + ']!';
Expand All @@ -523,6 +526,7 @@ public with sharing class TimelineService {

fieldDetails.put('value', fieldValue);
fieldDetails.put('label', fieldLabel);
fieldDetails.put('type', fieldType);

return fieldDetails;
}
Expand Down Expand Up @@ -634,6 +638,7 @@ public with sharing class TimelineService {
private String iconBackgroundField;
private String positionDateField;
private String positionDateValue;
private String positionDateType;
private String objectName;
private String type;
private String tooltipIdField;
Expand Down
43 changes: 28 additions & 15 deletions force-app/main/default/lwc/timeline/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,9 @@ export default class timeline extends NavigationMixin(LightningElement) {
let timelineResult = [];
let timelineTimes = [];

const options = {
hour: 'numeric',
minute: 'numeric',
year: 'numeric',
month: 'numeric',
day: 'numeric',
timeZone: TIMEZONE
};

const dateFormatter = new Intl.DateTimeFormat(me.calculatedLOCALE(), options);

result.forEach(function (record, index) {
let recordCopy = {};
let options;

recordCopy.recordId = record.objectId;
recordCopy.id = index;
Expand All @@ -461,9 +451,34 @@ export default class timeline extends NavigationMixin(LightningElement) {
recordCopy.objectName = record.objectName;
recordCopy.positionDateField = record.positionDateField;

let convertDate = record.positionDateValue.replace(' ', 'T');
convertDate = convertDate + '.000Z';
if (record.positionDateType === 'DATE') {
options = {
year: 'numeric',
month: 'numeric',
day: 'numeric'
};
}
else {
options = {
hour: 'numeric',
minute: 'numeric',
year: 'numeric',
month: 'numeric',
day: 'numeric',
timeZone: TIMEZONE
};
}

let dateFormatter = new Intl.DateTimeFormat(me.calculatedLOCALE(), options);

let convertDate = record.positionDateValue;


if (record.positionDateType === 'DATETIME') {
convertDate = record.positionDateValue.replace(' ', 'T');
convertDate = convertDate + '.000Z';
}

let localDate = new Date(convertDate);
let localPositionDate = dateFormatter.format(localDate);

Expand All @@ -472,10 +487,8 @@ export default class timeline extends NavigationMixin(LightningElement) {

recordCopy.detailField = record.detailField;
recordCopy.detailFieldLabel = record.detailFieldLabel;

recordCopy.fallbackTooltipField = record.fallbackTooltipField;
recordCopy.fallbackTooltipValue = record.fallbackTooltipValue;

recordCopy.tooltipId = record.tooltipId;
recordCopy.tooltipObject = record.tooltipObject;
recordCopy.drilldownId = record.drilldownId;
Expand Down

0 comments on commit 8ad3407

Please sign in to comment.