Skip to content

Commit

Permalink
exio-2146-display utc time to local time (#1759)
Browse files Browse the repository at this point in the history
* display utc time to local time

* unit tests fixed

* version updated

* convert utc time to local

* test

* unit tests fix

* unit tests fix

* updated tests

* unit test fix

* tests fix

* test

* test

* setting github run timezone to local time zone

* Update npmpublish.yml

* revert changes

* unit tests fix

* test

* test

* test

* test

* test fix

* Update case-file-view-folder.component.spec.ts

* Update case-file-view-folder.component.spec.ts

* Update case-file-view-folder.component.spec.ts

* removed console log

* release notes updated

* unused import of moment

* unused import of moment

* Update release-notes, update to release version

* Set version number on sonarcloud github action

---------

Co-authored-by: Josh-HMCTS <128602796+Josh-HMCTS@users.noreply.github.com>
Co-authored-by: olusegun odunukan <olusegun.odunukan@hmcts.net>
Co-authored-by: Josh <josh.glasgow@hmcts.net>
  • Loading branch information
4 people authored Oct 7, 2024
1 parent 3f620d9 commit 7cc8fe1
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
name: code-coverage-report
path: coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
uses: sonarsource/sonarcloud-github-action@v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## RELEASE NOTES

### Version 7.0.67
**EXUI-2146** Case file view time is 1 hour behind
**EXUI-2230** Case File View date/time as GMT rather than Local BST

### Version 7.0.66
**EXUI-2148** Additional checks on task completion from session storage
**EXUI-2057** A frozen screen is seen when attempting to complete a current task...
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": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.66",
"version": "7.0.67",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.66",
"version": "7.0.67",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span class="node__name node-name-document">
{{node.name}}
<br>
<span class="node__document-upload-timestamp">{{node.upload_timestamp | date:"dd MMM YYYY HH:mm"}}</span>
<span class="node__document-upload-timestamp">{{node.upload_timestamp | ccdDate : 'local' | date:"dd MMM YYYY HH:mm"}}</span>
</span>
<div class="node__document-options">
<ccd-case-file-view-folder-document-actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { plainToClass } from 'class-transformer';
import { of } from 'rxjs';
import { AbstractAppConfig } from '../../../../../../app.config';
import { CaseFileViewSortColumns, DocumentTreeNode, DocumentTreeNodeType } from '../../../../../domain/case-file-view';
import { DocumentManagementService, WindowService } from '../../../../../services';
import { DocumentManagementService, FormatTranslatorService, WindowService } from '../../../../../services';
import { mockDocumentManagementService } from '../../../../../services/document-management/document-management.service.mock';
import { categoriesAndDocumentsTestData } from '../../test-data/categories-and-documents-test-data';
import {
Expand All @@ -20,6 +20,8 @@ import {
} from '../../test-data/document-tree-node-test-data';
import { CaseFileViewFolderComponent, MEDIA_VIEWER_LOCALSTORAGE_KEY } from './case-file-view-folder.component';
import createSpyObj = jasmine.createSpyObj;
import { DatePipe } from '../../../utils';
import moment from 'moment-timezone';

describe('CaseFileViewFolderComponent', () => {
let component: CaseFileViewFolderComponent;
Expand All @@ -34,26 +36,50 @@ describe('CaseFileViewFolderComponent', () => {
document_filename: 'Lager encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: '11 May 2023 00:00:00'
upload_timestamp: '2023-05-11T11:15:10.00'
},
{
name: 'Beers encyclopedia',
type: DocumentTreeNodeType.DOCUMENT,
document_filename: 'Beers encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: '14 Apr 2023 00:00:00'
upload_timestamp: '2023-04-14T15:30:00.00'
},
{
name: 'Ale encyclopedia',
type: DocumentTreeNodeType.DOCUMENT,
document_filename: 'Ale encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: '12 Mar 2023 01:23:01'
upload_timestamp: '2023-03-12T01:23:01.00'
}
]);

// Method used to resolve discrepancies between GitHub Actions and local machine timezones.
// This function adjusts the given UTC date string to the local timezone of the machine
// running the code. It uses the Moment.js library to detect the current system's timezone
// dynamically and converts the date accordingly, formatting it to "D MMM YYYY HH:mm".
function adjustDateToLocal(dateString: Date | string): string {
// Determine the local time zone dynamically
const localTimeZone = moment.tz.guess();
console.log(`Detected Local Time Zone: ${localTimeZone}`);

// Create a Moment object from the date string in UTC
const utcDate = moment.tz(dateString, 'UTC');
console.log('Original UTC Date:', utcDate.format());

// Convert the UTC date to the local time zone
const localDate = utcDate.clone().tz(localTimeZone);
console.log(`Converted to Local Time (${localTimeZone}):`, localDate.format());

// Format the adjusted date to the desired string format: "11 May 2023 12:15"
const formattedDate = localDate.format('D MMM YYYY HH:mm');
console.log(`Formatted Date: ${formattedDate}`);

return formattedDate;
}

beforeEach(waitForAsync(() => {
const mockWindowService = createSpyObj<WindowService>('WindowService', ['setLocalStorage', 'openOnNewTab']);
mockAppConfig = jasmine.createSpyObj<AbstractAppConfig>('AbstractAppConfig', ['getEnableCaseFileViewVersion1_1']);
Expand All @@ -66,12 +92,14 @@ describe('CaseFileViewFolderComponent', () => {
MatDialogModule
],
declarations: [
CaseFileViewFolderComponent
CaseFileViewFolderComponent,
DatePipe
],
providers: [
{ provide: WindowService, useValue: mockWindowService },
{ provide: DocumentManagementService, useValue: mockDocumentManagementService },
{ provide: AbstractAppConfig, useValue: mockAppConfig }
{ provide: AbstractAppConfig, useValue: mockAppConfig },
FormatTranslatorService
]
}).compileComponents();

Expand All @@ -90,11 +118,11 @@ describe('CaseFileViewFolderComponent', () => {
documentFilterInputEl.dispatchEvent(new Event('input'));
fixture.detectChanges();
await fixture.whenStable();
component.sortDataSourceDescending(1)
component.sortDataSourceDescending(1);
fixture.detectChanges();
expect(component.filter).toHaveBeenCalled();

expect(treeData[3].children[0].upload_timestamp).toEqual('17 Nov 2022 00:00:00');
expect(treeData[3].children[0].upload_timestamp).toEqual('2022-11-17T00:00:00.00');
});

it('should generate tree data from categorised data', () => {
Expand All @@ -116,19 +144,24 @@ describe('CaseFileViewFolderComponent', () => {
fixture.detectChanges();
const documentTreeContainerEl = nativeElement.querySelector('.document-tree-container');
expect(documentTreeContainerEl).toBeDefined();

const timestampElements = nativeElement.querySelectorAll('.node__document-upload-timestamp');
expect(timestampElements[0].textContent).toEqual('11 May 2023 00:00');
expect(timestampElements[1].textContent).toEqual('14 Apr 2023 00:00');
expect(timestampElements[2].textContent).toEqual('12 Mar 2023 01:23');
expect(timestampElements[3].textContent).toEqual('');
expect(timestampElements[4].textContent).toEqual('10 Feb 2023 00:00');
expect(timestampElements[5].textContent).toEqual('12 Apr 2023 00:00');
expect(timestampElements[6].textContent).toEqual('16 Mar 2023 00:00');
expect(timestampElements[7].textContent).toEqual('21 Jun 2022 00:00');
expect(timestampElements[8].textContent).toEqual('04 Nov 2022 00:00');
expect(timestampElements[9].textContent).toEqual('28 Dec 2022 00:00');
expect(timestampElements[10].textContent).toEqual('17 Nov 2022 00:00');
expect(timestampElements[11].textContent).toEqual('23 Feb 2023 00:00');
const documents = categoriesAndDocumentsTestData.categories[0]?.documents || [];

// Loop over the timestamp elements and adjust based on the documents array length
timestampElements.forEach((element, index) => {
// Ensure the document exists at the current index
const document = documents[index];
if (!document) {
return; // Skip this iteration
}

// Adjust the document timestamp to local time
const adjustedTimestamp = adjustDateToLocal(document.upload_timestamp);

// Verify that the element's text content matches the adjusted timestamp
expect(element.textContent).toEqual(adjustedTimestamp);
});
});

it('should call sortChildrenAscending on all children of nestedDataSource when calling sortDataSourceAscAlphabetically', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angu
import { FormControl, FormGroup } from '@angular/forms';
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
import { Router } from '@angular/router';
import moment from 'moment/moment';
import { Observable, Subscription, of } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { AbstractAppConfig } from '../../../../../../app.config';
Expand Down Expand Up @@ -130,7 +129,7 @@ export class CaseFileViewFolderComponent implements OnInit, OnDestroy {
documentTreeNode.document_binary_url = document.document_binary_url;
documentTreeNode.attribute_path = document.attribute_path;
documentTreeNode.upload_timestamp = this.appConfig.getEnableCaseFileViewVersion1_1()
&& document.upload_timestamp ? moment(document.upload_timestamp).format('DD MMM YYYY HH:mm:ss') : '';
&& document.upload_timestamp ? document.upload_timestamp.toString() : '';

documentsToReturn.push(documentTreeNode);
});
Expand All @@ -148,7 +147,7 @@ export class CaseFileViewFolderComponent implements OnInit, OnDestroy {
documentTreeNode.document_binary_url = document.document_binary_url;
documentTreeNode.attribute_path = document.attribute_path;
documentTreeNode.upload_timestamp = this.appConfig.getEnableCaseFileViewVersion1_1()
&& document.upload_timestamp ? moment(document.upload_timestamp).format('DD MMM YYYY HH:mm:ss') : '';
&& document.upload_timestamp ? document.upload_timestamp.toString() : '';

documents.push(documentTreeNode);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ export const categoriesAndDocumentsTestData: CategoriesAndDocuments = {
document_filename: 'Lager encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 4, 11, 0, 0, 0, 0),
upload_timestamp: '2023-05-11T11:15:10.00',
content_type: ''
},
{
document_url: '/test',
document_filename: 'Beers encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 3, 14, 0, 0, 0, 0),
upload_timestamp: '2023-04-14T15:30:00.00',
content_type: ''
},
{
document_url: '/test',
document_filename: 'Ale encyclopedia',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 2, 12, 1, 23, 1, 0),
upload_timestamp: '2023-03-12T01:23:01.00',
content_type: ''
}
],
Expand Down Expand Up @@ -88,23 +88,23 @@ export const categoriesAndDocumentsTestData: CategoriesAndDocuments = {
document_filename: 'Details about white wine',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 1, 10, 0, 0, 0, 0),
upload_timestamp: '2023-02-10T00:00:00.00',
content_type: ''
},
{
document_url: '/prosecco',
document_filename: 'Details about Prosecco',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 3, 12, 0, 0, 0, 0),
upload_timestamp: '2023-04-12T00:00:00.00',
content_type: ''
},
{
document_url: '/pinot-grigio',
document_filename: 'Details about Pinot Grigio',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 2, 16, 0, 0, 0, 0),
upload_timestamp: '2023-03-16T00:00:00.00',
content_type: ''
}
],
Expand Down Expand Up @@ -155,7 +155,7 @@ export const categoriesAndDocumentsTestData: CategoriesAndDocuments = {
document_filename: 'Details about Whisky Lowland 1',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2022, 5, 21, 0, 0, 0, 0),
upload_timestamp: '2022-06-21T00:00:00.00',
content_type: ''
}
],
Expand All @@ -180,15 +180,15 @@ export const categoriesAndDocumentsTestData: CategoriesAndDocuments = {
document_filename: 'Details about Whisky Islay',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2022, 10, 4, 0, 0, 0, 0),
upload_timestamp: '2022-11-04T00:00:00.00',
content_type: ''
},
{
document_url: '/test',
document_filename: 'More information about Whisky Islay',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2022, 11, 28, 0, 0, 0, 0),
upload_timestamp: '2022-12-28T00:00:00.00',
content_type: ''
}
],
Expand Down Expand Up @@ -219,15 +219,15 @@ export const categoriesAndDocumentsTestData: CategoriesAndDocuments = {
document_filename: 'Uncategorised document 1',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2022, 10, 17, 0, 0, 0, 0),
upload_timestamp: '2022-11-17T00:00:00.00',
content_type: ''
},
{
document_url: '/uncategorised-document-2',
document_filename: 'Uncategorised document 2',
document_binary_url: '/test/binary',
attribute_path: '',
upload_timestamp: new Date(2023, 1, 23, 0, 0, 0, 0),
upload_timestamp: '2023-02-23T00:00:00.00',
content_type: ''
}
]
Expand Down
Loading

0 comments on commit 7cc8fe1

Please sign in to comment.