mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	timerender: Extract method to compute exact date-time from time.
				
					
				
			This commit is contained in:
		@@ -278,6 +278,18 @@ exports.absolute_time = (function () {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}());
 | 
					}());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exports.get_full_datetime = function (time) {
 | 
				
			||||||
 | 
					    // Convert to number of hours ahead/behind UTC.
 | 
				
			||||||
 | 
					    // The sign of getTimezoneOffset() is reversed wrt
 | 
				
			||||||
 | 
					    // the conventional meaning of UTC+n / UTC-n
 | 
				
			||||||
 | 
					    const tz_offset = -time.getTimezoneOffset() / 60;
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        date: time.toLocaleDateString(),
 | 
				
			||||||
 | 
					        time: time.toLocaleTimeString() +
 | 
				
			||||||
 | 
					        ' (UTC' + (tz_offset < 0 ? '' : '+') + tz_offset + ')',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// XDate.toLocaleDateString and XDate.toLocaleTimeString are
 | 
					// XDate.toLocaleDateString and XDate.toLocaleTimeString are
 | 
				
			||||||
// expensive, so we delay running the following code until we need
 | 
					// expensive, so we delay running the following code until we need
 | 
				
			||||||
// the full date and time strings.
 | 
					// the full date and time strings.
 | 
				
			||||||
@@ -287,14 +299,10 @@ exports.set_full_datetime = function timerender_set_full_datetime(message, time_
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const time = new XDate(message.timestamp * 1000);
 | 
					    const time = new XDate(message.timestamp * 1000);
 | 
				
			||||||
    // Convert to number of hours ahead/behind UTC.
 | 
					    const full_datetime = exports.get_full_datetime(time);
 | 
				
			||||||
    // The sign of getTimezoneOffset() is reversed wrt
 | 
					 | 
				
			||||||
    // the conventional meaning of UTC+n / UTC-n
 | 
					 | 
				
			||||||
    const tz_offset = -time.getTimezoneOffset() / 60;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    message.full_date_str = time.toLocaleDateString();
 | 
					    message.full_date_str = full_datetime.date;
 | 
				
			||||||
    message.full_time_str = time.toLocaleTimeString() +
 | 
					    message.full_time_str = full_datetime.time;
 | 
				
			||||||
        ' (UTC' + (tz_offset < 0 ? '' : '+') + tz_offset + ')';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    time_elem.attr('title', message.full_date_str + ' ' + message.full_time_str);
 | 
					    time_elem.attr('title', message.full_date_str + ' ' + message.full_time_str);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user