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

AP-82 - Timezone support for service definitions start and end times #186

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/models/appointmentService.js
Expand Up @@ -10,7 +10,14 @@ Bahmni.Appointments.AppointmentService = (function () {
var dateUtil = Bahmni.Common.Util.DateUtil;

var getTime = function (dateTime) {
return dateTime ? dateUtil.getDateTimeInSpecifiedFormat(dateTime, timeFormat) : undefined;
if (!dateTime) {
return undefined;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Return the time in UTC formatted as 'HH:mm:ss'.
Current date is used together with the passed time before converting UTC so that the returned time is ok whether we're currently on daylight saving time or not.

let now = new Date();
now.setHours(dateTime.getHours());
now.setMinutes(dateTime.getMinutes());
now.setSeconds(dateTime.getSeconds());
return ('0' + now.getUTCHours()).slice(-2) + ':' + ('0' + now.getUTCMinutes()).slice(-2) + ':' + ('0' + now.getUTCSeconds()).slice(-2);
};

var constructAvailabilityPerDay = function (result, availability) {
Expand Down
10 changes: 9 additions & 1 deletion src/models/appointmentServiceViewModel.js
Expand Up @@ -30,7 +30,15 @@ Bahmni.Appointments.AppointmentServiceViewModel = (function () {

Service.createFromResponse = function (serviceDetails) {
var getDateTime = function (time) {
return time ? new Date("January 01, 1970 " + time) : undefined;
if (!time) {
return undefined;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting the date with "January 01, 1970" would cause issues with daylight saving time. Use the current date instead so that the returned time is ok whether we're currently on daylight saving time or not.

let date = new Date();
date.setHours(time.split(':')[0]);
date.setMinutes(time.split(':')[1]);
date.setSeconds(time.split(':')[2]);
date.setMilliseconds(0);
return date;
};

var parseAvailability = function (avbsByDay) {
Expand Down
16 changes: 10 additions & 6 deletions test/controllers/admin/appointmentServiceController.spec.js
Expand Up @@ -176,8 +176,12 @@ describe("AppointmentServiceController", function () {
var dateUtil = Bahmni.Common.Util.DateUtil;
var timeFormat = 'HH:mm:ss';
beforeEach(function () {
startDateTime = new Date('1970-01-01T11:30:00.000Z');
endDateTime = new Date('1970-01-01T14:30:00.000Z');
startDateTime = new Date();
startDateTime.setHours(11, 30, 0);

endDateTime = new Date();
startDateTime.setHours(14, 30, 0);

serviceResponse = {
startTime: dateUtil.getDateTimeInSpecifiedFormat(startDateTime, timeFormat),
endTime: dateUtil.getDateTimeInSpecifiedFormat(endDateTime, timeFormat),
Expand Down Expand Up @@ -234,12 +238,12 @@ describe("AppointmentServiceController", function () {
scope.service = {
name: 'Chemotherapy',
description: 'For cancer',
startTime: new Date().toString(),
endTime: new Date().toString(),
startTime: new Date(),
endTime: new Date(),
initialAppointmentStatus: 'Requested',
weeklyAvailability: [{
startTime: new Date().toString(),
endTime: new Date().toString(),
startTime: new Date(),
endTime: new Date(),
days: [{name: 'MONDAY', isSelected: true}]
}]
};
Expand Down
8 changes: 6 additions & 2 deletions test/models/AppointmentServiceViewModel.spec.js
Expand Up @@ -4,8 +4,12 @@ describe('AppointmentServiceViewModel', function () {
var appointmentServiceModel;
var dateUtil = Bahmni.Common.Util.DateUtil;
var timeFormat = 'HH:mm:ss';
var startDateTime = new Date('1970-01-01T11:30:00.000Z');
var endDateTime = new Date('1970-01-01T14:30:00.000Z');

var startDateTime = new Date();
startDateTime.setHours(11, 30, 0);

var endDateTime = new Date();
startDateTime.setHours(14, 30, 0);

var serviceResponse = {
name: 'Ortho',
Expand Down
12 changes: 6 additions & 6 deletions test/models/appointmentService.spec.js
Expand Up @@ -54,8 +54,8 @@ describe('AppointmentService', function () {
});

it('should re arrange all weeklyAvailabilities by day', function () {
var startDateTime = new Date().toString();
var endDateTime = new Date().toString();
var startDateTime = new Date();
var endDateTime = new Date();

var days = angular.copy(constDays);
days[1].isSelected = true;
Expand All @@ -80,11 +80,11 @@ describe('AppointmentService', function () {
});

it('should construct weekly availability by day for multiple availabilities', function () {
var startDateTime = new Date().toString();
var endDateTime = new Date().toString();
var startDateTime = new Date();
var endDateTime = new Date();

var startDateTime2 = new Date("2015-10-01T18:30:00.000Z").toString();
var endDateTime2 = new Date("2015-10-01T18:30:00.000Z").toString();
var startDateTime2 = new Date("2015-10-01T18:30:00.000Z");
var endDateTime2 = new Date("2015-10-01T18:30:00.000Z");

var days1 = angular.copy(constDays);
days1[1].isSelected = true;
Expand Down