Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-3245 | Fix. Set Default Date Format #720

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/app/clinical/common/controllers/visitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ angular.module('bahmni.clinical')
};

$scope.displayDate = function (date) {
return moment(date).format("DD-MMM-YY");
return moment(date).format("DD-MMM-YYYY");
};

$scope.$on("event:printVisitTab", function () {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/clinical/consultation/views/bacteriology.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h2 class="section-title fl">{{'BACTERIOLOGY_TAB_TITLE_KEY' | translate}}</h2>
<div class="fl savedSpecimens-text">
<span>{{getDisplayName(savedSpecimen)}}</span>
<span>#{{savedSpecimen.identifier}}</span>
<span>{{ 'BACTERIOLOGY_ADDED_ON_KEY' | translate }} {{savedSpecimen.dateCollected | date: 'dd MMM yy'}}</span>
<span>{{ 'BACTERIOLOGY_ADDED_ON_KEY' | translate }} {{savedSpecimen.dateCollected | date: 'dd MMM yyyy'}}</span>
</div>
<div class="fr savedSpecimens-action">
<i class="fa fa-pencil" ng-click="editSpecimen(savedSpecimen)"></i>
Expand Down
2 changes: 1 addition & 1 deletion ui/app/common/ui-helper/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ angular.module('bahmni.common.uiHelper')
var link = function ($scope, element, attrs, ngModel) {
var maxDate = attrs.maxDate;
var minDate = attrs.minDate || "-120y";
var format = attrs.dateFormat || 'dd-mm-yy';
var format = attrs.dateFormat || 'dd-mm-yyyy';
element.datepicker({
changeYear: true,
changeMonth: true,
Expand Down
10 changes: 5 additions & 5 deletions ui/app/common/util/dateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Bahmni.Common.Util.DateUtil = {
},

getDateInMonthsAndYears: function (date, format) {
var format = format || "MMM YY";
var format = format || "MMM YYYY";
var dateRepresentation = isNaN(Number(date)) ? date : Number(date);
if (!moment(dateRepresentation).isValid()) {
return date;
Expand All @@ -96,24 +96,24 @@ Bahmni.Common.Util.DateUtil = {
if (!moment(dateRepresentation).isValid()) {
return datetime;
}
return dateRepresentation ? moment(dateRepresentation).format("DD MMM YY h:mm a") : null;
return dateRepresentation ? moment(dateRepresentation).format("DD MMM YYYY h:mm a") : null;
},

formatDateWithoutTime: function (date) {
var dateRepresentation = isNaN(Number(date)) ? date : Number(date);
if (!moment(dateRepresentation).isValid()) {
return date;
}
return dateRepresentation ? moment(dateRepresentation).format("DD MMM YY") : null;
return dateRepresentation ? moment(dateRepresentation).format("DD MMM YYYY") : null;
},

formatDateInStrictMode: function (date) {
var dateRepresentation = isNaN(Number(date)) ? date : Number(date);
if (moment(dateRepresentation, 'YYYY-MM-DD', true).isValid()) {
return moment(dateRepresentation).format("DD MMM YY");
return moment(dateRepresentation).format("DD MMM YYYY");
}
if (moment(dateRepresentation, 'YYYY-MM-DDTHH:mm:ss.SSSZZ', true).isValid()) {
return moment(dateRepresentation).format("DD MMM YY");
return moment(dateRepresentation).format("DD MMM YYYY");
}
return date;
},
Expand Down
4 changes: 2 additions & 2 deletions ui/app/reports/views/myReports.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ <h2 class="section-title">{{::'REPORTS_QUEUE' | translate}}</h2>
<tr ng-repeat="report in reports[day.unixTimeStamp]" ng-hide="report.hidden">
<td>{{:: report.name }}</td>
<td>{{ :: convertToDate(report.requestDatetime , 'hh:mm A')}}</td>
<td>{{ :: convertToDate(report.startDate , "DD MMM YY")}}</td>
<td>{{ :: convertToDate(report.endDate , "DD MMM YY")}}</td>
<td>{{ :: convertToDate(report.startDate , "DD MMM YYYY")}}</td>
<td>{{ :: convertToDate(report.endDate , "DD MMM YYYY")}}</td>
<td> {{ :: getFormat(report.format) }}</td>
<td ng-if="report.status != 'Completed' && report.status != 'Error'" class="reportStatus reportStatus--{{report.status}}">{{ report.status }}</td>
<td ng-if="report.status == 'Completed'" class="reportStatus reportStatus--link">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('VisitController', function () {
});

it('should check data format', function () {
expect(scope.displayDate(new Date('2014', '7', '15', '12'))).toBe('15-Aug-14');
expect(scope.displayDate(new Date('2014', '7', '15', '12'))).toBe('15-Aug-2014');
});

it('should check test result class for expected style', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ describe('obsToObsFlowSheet DisplayControl', function () {
}
];

expect(compiledElementScope.commafy(observations)).toEqual("10 Oct 15");
expect(compiledElementScope.commafy(observations)).toEqual("10 Oct 2015");
});

it('should return just month and year if the concept datatype is date and configured to show month and year', function () {
Expand Down Expand Up @@ -662,7 +662,7 @@ describe('obsToObsFlowSheet DisplayControl', function () {
}
];

expect(compiledElementScope.commafy(observations)).toEqual("Oct 15");
expect(compiledElementScope.commafy(observations)).toEqual("Oct 2015");
});

it('should return abbreviation of the coded answer if the concept is coded and configured to show abbreviation', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("OrdersDisplayControl", function () {
var compiledElementScope = element.isolateScope();
scope.$digest();

var expectedDate = moment(orders[0].orderDate).format("DD MMM YY h:mm a");
var expectedDate = moment(orders[0].orderDate).format("DD MMM YYYY h:mm a");
expect(compiledElementScope.getTitle(orders[0])).toBe("Absconding on " + expectedDate + " by Surajkumar Surajkumar Surajkumar")
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Observation Value Mapper", function () {

it("should return datetime value", function() {
var obs = {type: "Datetime", value: "2015-12-05 16:02:00", concept: {}};
expect(mapper.map(obs)).toBe("05 Dec 15 4:02 pm");
expect(mapper.map(obs)).toBe("05 Dec 2015 4:02 pm");
});

it("should return multiselect values", function() {
Expand Down
2 changes: 1 addition & 1 deletion ui/test/unit/common/models/age.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Age", function(){
var age = ageFactory.create(0, 0, 0);
var birthDate = dateUtil.now();

expect(moment(ageFactory.calculateBirthDate(age)).format("DD MMM YY").toString()).toEqual(moment(birthDate).format("DD MMM YY").toString());
expect(moment(ageFactory.calculateBirthDate(age)).format("DD MMM YYYY").toString()).toEqual(moment(birthDate).format("DD MMM YYYY").toString());
});

it("should return date of birth", function(){
Expand Down
2 changes: 1 addition & 1 deletion ui/test/unit/common/obs/directives/showObservation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("ensure that the directive show-observation works properly", function (
scope.$digest();

expect(compiledScope).not.toBeUndefined();
expect(compiledScope.dateString(observation)).toBe(moment(obsDate).format("DD MMM YY h:mm a"));
expect(compiledScope.dateString(observation)).toBe(moment(obsDate).format("DD MMM YYYY h:mm a"));
});

it("should open video in a new dialog", function () {
Expand Down
8 changes: 4 additions & 4 deletions ui/test/unit/common/obs/observation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Observation", function () {

it("should return datetime in specific format", function () {
var observation = new Observation({"type": "Datetime", "value": "2014-12-05 17:00:00"});
expect(observation.getDisplayValue()).toBe("05 Dec 14 5:00 pm");
expect(observation.getDisplayValue()).toBe("05 Dec 2014 5:00 pm");
});

it("should return empty if value is null", function () {
Expand All @@ -71,15 +71,15 @@ describe("Observation", function () {

it("should format date to bahmniDate if value is of type date", function () {
var observation = new Observation({"type": "Date", "value": "2012-12-10"});
expect(observation.getDisplayValue()).toBe("10 Dec 12");
expect(observation.getDisplayValue()).toBe("10 Dec 2012");
});
it("should format date in months and years if config is set to display in months and years", function(){
var observation = new Observation({"type": "Date", "value": "2012-12-10"},{"displayMonthAndYear": true});
expect((observation.getDisplayValue())).toBe("Dec 12");
expect((observation.getDisplayValue())).toBe("Dec 2012");
});
it("should format date in text to months and years if config is set to display in months and years", function(){
var observation = new Observation({"type": "text", "value": "2012-12-10"},{"displayMonthAndYear": true});
expect((observation.getDisplayValue())).toBe("Dec 12");
expect((observation.getDisplayValue())).toBe("Dec 2012");
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ describe("ManageProgramController", function () {
scope.updatePatientProgram(patientProgramToBeUpdated);

expect(messageService.showMessage)
.toHaveBeenCalledWith("error", "PROGRAM_MANAGEMENT_STATE_CANT_START_BEFORE_KEY (15 Jul 15)");
.toHaveBeenCalledWith("error", "PROGRAM_MANAGEMENT_STATE_CANT_START_BEFORE_KEY (15 Jul 2015)");
});

it("should transit from one state to another successfully only if different state is selected", function () {
Expand Down Expand Up @@ -473,7 +473,7 @@ describe("ManageProgramController", function () {

scope.updatePatientProgram(programToBeUpdated);

expect(messageService.showMessage).toHaveBeenCalledWith("error", "PROGRAM_MANAGEMENT_PROGRAM_CANT_END_BEFORE_KEY (15 Jul 15)");
expect(messageService.showMessage).toHaveBeenCalledWith("error", "PROGRAM_MANAGEMENT_PROGRAM_CANT_END_BEFORE_KEY (15 Jul 2015)");
});

it('should end a program successfully', function () {
Expand Down
18 changes: 9 additions & 9 deletions ui/test/unit/common/util/dateUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ describe('DateUtil', function () {
describe("formatDateWithTime", function () {
it("should take a long representation of date and format", function () {
var date = new Date(1427803080000);
expect(dateUtil.formatDateWithTime("1427803080000")).toEqual(moment(date).format("DD MMM YY h:mm a"));
expect(dateUtil.formatDateWithTime("1427803080000")).toEqual(moment(date).format("DD MMM YYYY h:mm a"));
});

it("should take a string representation of date and format", function () {
var date = new Date();
expect(dateUtil.formatDateWithTime(moment(date).format(dateFormat))).toEqual(moment(date).format("DD MMM YY h:mm a"));
expect(dateUtil.formatDateWithTime(moment(date).format(dateFormat))).toEqual(moment(date).format("DD MMM YYYY h:mm a"));
});

it("should not break for undefined and return null", function () {
Expand All @@ -278,12 +278,12 @@ describe('DateUtil', function () {
describe("formatDateWithoutTime", function () {
it("should take a long representation of date and format", function () {
var date = new Date(1427803080000);
expect(dateUtil.formatDateWithoutTime("1427803080000")).toEqual(moment(date).format("DD MMM YY"));
expect(dateUtil.formatDateWithoutTime("1427803080000")).toEqual(moment(date).format("DD MMM YYYY"));
});

it("should take a string representation of date and format", function () {
var date = new Date();
expect(dateUtil.formatDateWithoutTime(moment(date).format(dateFormat))).toEqual(moment(date).format("DD MMM YY"));
expect(dateUtil.formatDateWithoutTime(moment(date).format(dateFormat))).toEqual(moment(date).format("DD MMM YYYY"));
});

it("should not break for undefined and return null", function () {
Expand Down Expand Up @@ -345,17 +345,17 @@ describe('DateUtil', function () {

describe("getDateWithMonthsAndYears", function(){
it("should return date with months and years", function(){
expect(dateUtil.getDateInMonthsAndYears(new Date('2014', '7', '15', '12','30','25'))).toBe('Aug 14');
expect(dateUtil.getDateInMonthsAndYears(new Date('2014', '7', '15', '12','30','25'))).toBe('Aug 2014');
});
});

describe("formatDateInStrictMode", function(){
it("should return date in dd MMM yy format when date with yyyy-MM-dd format is passed", function(){
expect(dateUtil.formatDateInStrictMode('2016-02-10')).toBe('10 Feb 16');
it("should return date in dd MMM YYYY format when date with yyyy-MM-dd format is passed", function(){
expect(dateUtil.formatDateInStrictMode('2016-02-10')).toBe('10 Feb 2016');
});

it("should return date in dd MMM yy format when date with yyyy-MM-ddTHH:mm:ss.SSSZ is passed", function(){
expect(dateUtil.formatDateInStrictMode('2016-03-01T10:30:00.000+0530')).toBe(moment('2016-03-01T10:30:00.000+0530').format('DD MMM YY'));
it("should return date in dd MMM YYYY format when date with yyyy-MM-ddTHH:mm:ss.SSSZ is passed", function(){
expect(dateUtil.formatDateInStrictMode('2016-03-01T10:30:00.000+0530')).toBe(moment('2016-03-01T10:30:00.000+0530').format('DD MMM YYYY'));
});

it("should return the string if the format does not match yyyy-MM-dd or yyyy-MM-ddTHH:mm:ss.SSSZ", function(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("MyReportsController", function () {

it("should convert unixTimeStamps to given format", function () {
expect(scope.convertToDate(1474529795000, 'hh:mm A')).toEqual(moment(1474529795000).format('hh:mm A'));
expect(scope.convertToDate(1474529795000, "DD MMM YY")).toEqual(moment(1474529795000).format('DD MMM YY'));
expect(scope.convertToDate(1474529795000, "DD MMM YYYY")).toEqual(moment(1474529795000).format('DD MMM YYYY'));
expect(scope.convertToDate(1474529795000, "MMMM Do YYYY, dddd")).toEqual(moment(1474529795000).format('MMMM Do YYYY, dddd'));
});

Expand Down
Loading