diff --git a/src/front/components/reports/PhotoCapture.js b/src/front/components/reports/PhotoCapture.js index 66baa943..2c0b90e9 100644 --- a/src/front/components/reports/PhotoCapture.js +++ b/src/front/components/reports/PhotoCapture.js @@ -17,36 +17,9 @@ import { useAsyncError, } from '../../services/utilities'; import Spinner from '../Spinner'; +import { getCoordinatesFromExif, getDateFromExif } from './photoUtils'; const THUMBNAIL_SIZE = 110; -export function getCoordinatesFromExif(exif) { - if (exif?.GPSLatitude && exif?.GPSLongitude) { - let longitude = parseFloat(exif.GPSLongitude, 10); - let latitude = parseFloat(exif.GPSLatitude, 10); - longitude = longitude < 0 ? longitude : -longitude; - - return { latitude, longitude }; - } - - return null; -} - -export function getDateFromExif(exif) { - if (exif?.DateTimeOriginal) { - const parts = exif.DateTimeOriginal.split(' '); - const dateString = `${parts[0].replace(/:/g, '-')}T${parts[1]}Z`; - - const date = new Date(dateString); - - // exif date string is in the current timezone of the device - // we need to adjust it to UTC - date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); - - return date.toISOString(); - } - - return null; -} const displayCameraActivityFailedAlert = () => { Alert.alert( diff --git a/src/front/components/reports/photoUtils.js b/src/front/components/reports/photoUtils.js new file mode 100644 index 00000000..0703de54 --- /dev/null +++ b/src/front/components/reports/photoUtils.js @@ -0,0 +1,28 @@ +export function getCoordinatesFromExif(exif) { + if (exif?.GPSLatitude && exif?.GPSLongitude) { + let longitude = parseFloat(exif.GPSLongitude, 10); + let latitude = parseFloat(exif.GPSLatitude, 10); + longitude = longitude < 0 ? longitude : -longitude; + + return { latitude, longitude }; + } + + return null; +} + +export function getDateFromExif(exif) { + if (exif?.DateTimeOriginal) { + const parts = exif.DateTimeOriginal.split(' '); + const dateString = `${parts[0].replace(/:/g, '-')}T${parts[1]}Z`; + + const date = new Date(dateString); + + // exif date string is in the current timezone of the device + // we need to adjust it to UTC + date.setMinutes(date.getMinutes() + date.getTimezoneOffset()); + + return date.toISOString(); + } + + return null; +} diff --git a/src/front/components/reports/PhotoCapture.test.js b/src/front/components/reports/photoUtils.test.js similarity index 94% rename from src/front/components/reports/PhotoCapture.test.js rename to src/front/components/reports/photoUtils.test.js index 27db6ac2..1e99f632 100644 --- a/src/front/components/reports/PhotoCapture.test.js +++ b/src/front/components/reports/photoUtils.test.js @@ -1,4 +1,4 @@ -import { getCoordinatesFromExif, getDateFromExif } from './PhotoCapture'; +import { getCoordinatesFromExif, getDateFromExif } from './photoUtils'; describe('PhotoCapture', () => { describe('getCoordinatesFromExif', () => {