Skip to content

Commit

Permalink
[Parvathy, Rahul] | BAH-3245 | Fix. Set Default Date Format
Browse files Browse the repository at this point in the history
Co-authored-by: Parvathy Babu <parvathy.babu@thoughtworks.com>

The default year format is YYYY
  • Loading branch information
rahu1ramesh committed Oct 4, 2023
1 parent c144366 commit c10a765
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
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
8 changes: 4 additions & 4 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 @@ -104,16 +104,16 @@ Bahmni.Common.Util.DateUtil = {
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
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
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
6 changes: 3 additions & 3 deletions ui/test/unit/common/obs/observation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions ui/test/unit/common/util/dateUtil.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c10a765

Please sign in to comment.