@gooin/garmin-connect
Version:
Makes it simple to interface with Garmin Connect to get or set any data point
38 lines • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLocalTimestamp = exports.calculateTimeDifference = exports.toDateString = void 0;
function toDateString(date) {
const offset = date.getTimezoneOffset();
const offsetDate = new Date(date.getTime() - offset * 60 * 1000);
const [dateString] = offsetDate.toISOString().split('T');
return dateString;
}
exports.toDateString = toDateString;
function calculateTimeDifference(sleepStartTimestampGMT, sleepEndTimestampGMT) {
// Calculate time difference in seconds
const timeDifferenceInSeconds = (sleepEndTimestampGMT - sleepStartTimestampGMT) / 1000;
// Convert time difference to hours and minutes
const hours = Math.floor(timeDifferenceInSeconds / 3600);
const minutes = Math.floor((timeDifferenceInSeconds % 3600) / 60);
return {
hours,
minutes
};
}
exports.calculateTimeDifference = calculateTimeDifference;
function getLocalTimestamp(date, timezone) {
// Get the current local date timestamp in ISO format
const localTimestampISO = date.toISOString().substring(0, 23);
// Convert the ISO timestamp to local timezone while maintaining the same format
const localTimestamp = new Date(localTimestampISO).toLocaleString('en-US', {
timeZone: timezone,
hour12: false
});
// Format the local timestamp as `YYYY-MM-DDTHH:MM:SS.SSS`
const formattedLocalTimestamp = new Date(localTimestamp)
.toISOString()
.substring(0, 23);
return formattedLocalTimestamp;
}
exports.getLocalTimestamp = getLocalTimestamp;
//# sourceMappingURL=DateUtils.js.map