Package PamUtils
Class PamCalendar
java.lang.Object
PamUtils.PamCalendar
- Author:
- Doug Gillespie Date and time in Pamguard are critical. It's likely that we'll be taking time from the GPS in the longer term, so for now, make sure that all calendar functions come via this
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
createFileName
(long fileStartTime, String prefix, String fileType) Creates a file name containing the time and a user defined prefix and file endstatic String
createFileName
(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other informationstatic String
createFileName
(String directory, String prefix, String fileType) Create a file name that doesn't contain a timestatic String
createFileNameMillis
(long fileStartTime, String prefix, String fileType) Like createFileName but the time now also includes milliseconds.static String
createFileNameMillis
(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other informationstatic Date
dateFromDateString
(String dateString, boolean useLocal) Read a date string and turn it into a Datestatic long
dateNumtoMillis
(double datenum) Convert MATLAB datenum to millis;static long
excelSerialtoMillis
(double excelSerial) Converts excel Serial date number (Jan 1900 format) to millis.static String
formatCompactDate
(long timeMillis, boolean useLocal) Format date in format "yyyyMMdd" using GMT as the time zonestatic String
formatDate
(long timeInMillis) Format the data in the dd MMMM yyyy formatstatic String
formatDate
(long timeInMillis, boolean useLocal) Format the data in the dd MMMM yyyy formatstatic String
formatDate2
(long timeInMillis, boolean useLocal) Format the data in the yyMMdd formatstatic String
formatDateTime
(long timeInMillis) Formats the time and data in a long formatstatic String
formatDateTime
(long timeInMillis, boolean useLocal) Formats the time and data in a long formatstatic String
formatDateTime
(Date date) static String
formatDateTime
(Date date, boolean useLocal) Get a formatted date and time string.static String
formatDateTime2
(long timeInMillis) Formats the time and data in a long format but without the GMT label at the end.static String
formatDateTime2
(long timeInMillis, boolean useLocal) Formats the time and data in a long format but without the GMT label at the end.static String
formatDateTime2
(long timeInMillis, String format, boolean useLocal) Formats the time and data in a long format but without the GMT label at the end.static String
formatDBDate
(long timeInMillis) Formats the date and time in the correct format for database output.static String
formatDBDateTime
(long timeInMillis) Formats the date and time in the correct format for database output.static String
formatDBDateTime
(long timeInMillis, boolean showMillis) Formats the date and time in the correct format for database output.static String
formatDBStyleTime
(long timeInMillis, boolean showMillis, boolean useLocal) static String
formatDuration
(long timeInMillis) Format a time in milliseconds as a number of days / seconds, etc.static String
formatDuration
(long timeInMillis, String middleString) static String
formatDuration
(long timeInMillis, String middleString1, String middleString2) static String
formatFileDate
(long timeMillis) Format date in format "yyyyMMdd" but using a time zone based on UTC or a local time depending on global PAMGuard options.static String
formatFileDate
(long timeMillis, boolean useLocal) Format date in format "yyyyMMdd" but using a time zone based on UTC or a local time depending on global PAMGuard options.static String
formatFileDateTime
(long timeMillis, boolean useLocal) Format date and time in format "yyyyMMdd_HHmmss"static String
formatLocalDateTime
(long timeInMillis) Formats the local time and data in a long formatstatic String
formatLocalDateTime
(Date date) Get a formatted local date and time string.static String
formatLocalDateTime2
(long timeInMillis) Formats the local time and date in a long format - identical to formatDateTime2(long), but using the local-PC time zonestatic String
formatLocalDateTime2
(long timeInMillis, String format, boolean useLocal) Get a formatted local date and time string - identical to formatDateTime2(long, String), but using the local-PC time zonestatic String
formatLocalDBDateTime
(long timeInMillis) Formats the date and time in the correct format for database output but in local time.static String
formatLocalFileDateTime
(long timeMillis) Format date and time in format "yyyyMMdd_HHmmss", but using the local pc time zonestatic String
formatLocalTime
(long timeMillis, boolean showMillis) Format a time string optionally showing the milliseconds with a given precision for UTC time zonestatic String
formatTime
(long timeMillis) Format a time string in the format HH:MM:SSstatic String
formatTime
(long timeMillis, boolean showMills) Format a time string in the format HH:MM:SSstatic String
formatTime
(long timeMillis, boolean showMillis, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision for UTC time zonestatic String
formatTime
(long timeMillis, int millisDigits) Format a time string optionally showing the milliseconds with a given precision.static String
formatTime
(long timeMillis, int millisDigits, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision.static String
formatTime2
(long timeMillis, int millisDigits, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision.static String
formatTodaysTime
(long timeInMillis) static String
formatTodaysTime
(long timeInMillis, boolean useLocal) static Calendar
Get the current datestatic Calendar
getCalendarDate
(long timeInMillis) Get the date for a given timestatic String
getDate()
static TimeZone
getDisplayTimeZone
(boolean useLocal) static long
static long
getTime()
a formatted time stringstatic long
Get a time correction added to all calls to gettimemillis();static long
If files are being analysed, return the time based on the file position.static String
getUnpunctuatedDate
(boolean useLocal) static long
static long
static final boolean
isSameDay
(long t1, long t2) Compares two times in milliseconds to see if they are on the same day or not.static boolean
static Long
millisFromDateString
(String dateString, boolean useLocal) Convert a date string into a millisecond time.static long
millisFromDateTimeString
(String dateTime, boolean stringInUTC) Return the time in milliseconds from the passed String sing the format "dd MMM yyyy HH:mm:ss"static long
millisFromDateTimeString
(String dateTime, String format, boolean stringInUTC) Return the time in milliseconds from the passed String, using the passed formatstatic double
millistoDateNum
(long timeMillis) Convert millis to MATLAB datenum.static double
millistoExcelSerial
(long timeMillis) Converts millis to an excel serial data based on the Jan 1900 system.static long
millisToUnixEpoch
(long millis) Convert to Unix Epoch.static long
msFromDate
(int year, int month, int day, int hour, int minute, int second, int millis) Convert date values to millisecond timestatic long
msFromDateString
(String dateString) Read a date string and turn it into a millisecond time.static long
msFromDateString
(String dateString, boolean useLocal) Read a date string and turn it into a millisecond time.static long
msFromTimeString
(String timeString) Read a time string and turn it into a millisecond time.static long
msFromTimeString
(String timeString, boolean useLocal) Read a time string and turn it into a millisecond time.static Long
readTimeDuration
(String duration) Read the duration and convert back to millis.static void
setSessionStartTime
(long sessionStartTime) static void
setSoundFile
(boolean soundFile) static void
setSoundFileTimeInMillis
(long soundFileTimeMillis) Relative time within a sound file.static void
setTimeCorrection
(long correction) Set a time correction to add to all calls to gettimemillis();static void
setViewPosition
(long viewPosition) static void
setViewTimes
(long start, long end) static Date
timeFromTimeString
(String timeString, boolean useLocal) Read a time string and turn it into a Datestatic Long
unpackStandardDateTime
(String numstr) static Date
unpackUnknownDateString
(String numstr)
-
Field Details
-
defaultTimeZone
-
millisPerDay
public static final long millisPerDay- See Also:
-
-
Constructor Details
-
PamCalendar
public PamCalendar()
-
-
Method Details
-
getTimeInMillis
public static long getTimeInMillis()If files are being analysed, return the time based on the file position. Otherwise just take the normal system time.- Returns:
- time in milliseconds
-
getTime
public static long getTime()a formatted time string -
getDate
- Returns:
- a formatted date string
-
isSameDay
public static final boolean isSameDay(long t1, long t2) Compares two times in milliseconds to see if they are on the same day or not.- Parameters:
t1
- first timet2
- second time- Returns:
- true if times are on the same day
-
getCalendarDate
Get the current date- Returns:
- the date as a Calendar object (in GMT)
-
getCalendarDate
Get the date for a given time- Parameters:
timeInMillis
- time in milliseconds- Returns:
- the date as a Calendar object (in GMT)
-
getDisplayTimeZone
-
formatDateTime
-
formatDateTime
Get a formatted date and time string.- Parameters:
date
- Date- Returns:
- formatted String
-
formatDateTime
Formats the time and data in a long format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatDateTime
Formats the time and data in a long format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatTodaysTime
-
formatTodaysTime
-
formatLocalDateTime
Formats the local time and data in a long format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatLocalDateTime
Get a formatted local date and time string.- Parameters:
date
- Date- Returns:
- formatted String
-
formatLocalDateTime2
Formats the local time and date in a long format - identical to formatDateTime2(long), but using the local-PC time zone- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated local date and time
-
formatLocalDateTime2
Get a formatted local date and time string - identical to formatDateTime2(long, String), but using the local-PC time zone- Parameters:
timeInMillis
- time in millisecondsthe
- output format. e.g. "dd MMM yyyy HH:mm:ss"- Returns:
- formated date and time
-
formatDateTime2
Formats the time and data in a long format but without the GMT label at the end.- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatDateTime2
Formats the time and data in a long format but without the GMT label at the end.- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatDateTime2
Formats the time and data in a long format but without the GMT label at the end.- Parameters:
timeInMillis
- time in millisecondsthe
- output format. e.g. "dd MMM yyyy HH:mm:ss"- Returns:
- formated data and time
-
millisFromDateTimeString
Return the time in milliseconds from the passed String sing the format "dd MMM yyyy HH:mm:ss"- Parameters:
dateTime
- The date and time to parsestringInUTC
- true if the passed String is in UTC time, or false if in local PC time- Returns:
- epoch time (elapsed time in milliseconds from Jan 1, 1970)
-
millisFromDateTimeString
Return the time in milliseconds from the passed String, using the passed format- Parameters:
dateTime
- The date and time to parseformat
- The date/time format to usestringInUTC
- true if the passed String is in UTC time, or false if in local PC time- Returns:
- epoch time (elapsed time in milliseconds from Jan 1, 1970)
-
formatDBDateTime
Formats the date and time in the correct format for database output."yyyy-MM-dd HH:mm:ss"
- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatDBDateTime
Formats the date and time in the correct format for database output."yyyy-MM-dd HH:mm:ss"
- Parameters:
timeInMillis
- time in millisecondsshowMills
- also show millseconds.- Returns:
- formated data and time
-
formatDBStyleTime
-
formatLocalDBDateTime
Formats the date and time in the correct format for database output but in local time."yyyy-MM-dd HH:mm:ss"
- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatDBDate
Formats the date and time in the correct format for database output."yyyy-MM-dd" This will always be UTC since it's data !
- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formated data and time
-
formatTime
Format a time string in the format HH:MM:SS- Parameters:
timeMillis
- time in milliseconds- Returns:
- formatted string
-
formatTime
Format a time string in the format HH:MM:SS- Parameters:
timeMillis
- time in milliseconds- Returns:
- formatted string
-
formatTime
Format a time string optionally showing the milliseconds with a given precision for UTC time zone- Parameters:
timeMillis
- time in millisecondsmillisDigits
- number of millisecond decimal places.- Returns:
- formatted time string.
-
formatLocalTime
Format a time string optionally showing the milliseconds with a given precision for UTC time zone- Parameters:
timeMillis
- time in millisecondsmillisDigits
- number of millisecond decimal places.- Returns:
- formatted time string.
-
formatTime
Format a time string optionally showing the milliseconds with a given precision. The time string is formatted as HH:mm:ss.SSSSS.- Parameters:
timeMillis
- time in millisecondsmillisDigits
- number of millsecond decimal places.- Returns:
- formatted time string.
-
formatTime
Format a time string optionally showing the milliseconds with a given precision. The time string is formatted as HH:mm:ss.SSSSS.- Parameters:
timeMillis
- time in millisecondsmillisDigits
- number of millsecond decimal places.- Returns:
- formatted time string.
-
formatTime2
Format a time string optionally showing the milliseconds with a given precision. The time string is formatted as HHmmss.SSSSS.- Parameters:
timeMillis
- time in millisecondsmillisDigits
- number of millsecond decimal places.- Returns:
- formatted time string.
-
formatDuration
Format a time in milliseconds as a number of days / seconds, etc.- Parameters:
timeInMillis
- time in milliseconds.- Returns:
- formatted time interval
-
formatDuration
-
formatDuration
-
formatDate
Format the data in the dd MMMM yyyy format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formatted string.
-
formatDate
Format the data in the dd MMMM yyyy format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formatted string.
-
formatDate2
Format the data in the yyMMdd format- Parameters:
timeInMillis
- time in milliseconds- Returns:
- formatted string.
-
formatCompactDate
Format date in format "yyyyMMdd" using GMT as the time zone- Parameters:
timeMillis
-- Returns:
-
formatFileDate
Format date in format "yyyyMMdd" but using a time zone based on UTC or a local time depending on global PAMGuard options.- Parameters:
timeMillis
-- Returns:
- formatted date string
-
formatFileDate
Format date in format "yyyyMMdd" but using a time zone based on UTC or a local time depending on global PAMGuard options.- Parameters:
timeMillis
-- Returns:
- formatted date string
-
formatFileDateTime
Format date and time in format "yyyyMMdd_HHmmss"- Parameters:
timeMillis
-- Returns:
- formatted time string
-
formatLocalFileDateTime
Format date and time in format "yyyyMMdd_HHmmss", but using the local pc time zone- Parameters:
timeMillis
-- Returns:
- formatted time string
-
msFromDateString
Read a date string and turn it into a millisecond time.- Parameters:
dateString
-- Returns:
- time in milliseconds
-
msFromDateString
Read a date string and turn it into a millisecond time.- Parameters:
dateString
-- Returns:
- time in milliseconds
-
millisFromDateString
Convert a date string into a millisecond time. Return null if the string cannot be interpreted as a date.- Parameters:
dateString
- Date string- Returns:
- Millis from 1970 or null.
-
dateFromDateString
Read a date string and turn it into a Date- Parameters:
dateString
-- Returns:
- time as a Date object
-
msFromTimeString
Read a time string and turn it into a millisecond time.- Parameters:
timeString
-- Returns:
- time in milliseconds
-
msFromTimeString
Read a time string and turn it into a millisecond time.- Parameters:
timeString
-useLocal
- use local time, not UTC- Returns:
- time in milliseconds
-
timeFromTimeString
Read a time string and turn it into a Date- Parameters:
timeString
-- Returns:
- time as a Date object
-
isSoundFile
public static boolean isSoundFile()- Returns:
- true if the sound source is a file
-
setSoundFile
public static void setSoundFile(boolean soundFile) - Parameters:
soundFile
- set whether the sound source is a file
-
getSessionStartTime
public static long getSessionStartTime()- Returns:
- The time that processing started
-
setSessionStartTime
public static void setSessionStartTime(long sessionStartTime) - Parameters:
sessionStartTime
- the time that processing started
-
setSoundFileTimeInMillis
public static void setSoundFileTimeInMillis(long soundFileTimeMillis) Relative time within a sound file. This is always just added to sessionStartTime to give an absolute time.- Parameters:
soundFileTimeMillis
- The relative time of a sound file.
-
createFileName
public static String createFileName(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other information- Parameters:
fileStartTime
- File timedirectory
- Directory / folderprefix
- file prefix (part of file name to inlcude before the time stamp)fileType
- file end- Returns:
- File path and name, ending with a time stamp
-
createFileNameMillis
public static String createFileNameMillis(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other information- Parameters:
fileStartTime
- File timedirectory
- Directory / folderprefix
- file prefix (part of file name to include before the time stamp)fileType
- file end- Returns:
- File path and name, ending with a time stamp
-
unpackStandardDateTime
-
unpackUnknownDateString
-
createFileName
Create a file name that doesn't contain a time- Parameters:
directory
- Directory / folderprefix
- file prefix (part of file name to inlcude before the time stamp)fileType
- file end- Returns:
- File path and name
-
createFileName
Creates a file name containing the time and a user defined prefix and file end- Parameters:
fileStartTime
- timeprefix
- prefix for file namefileType
- file type (with or without the '.')- Returns:
- file name
-
createFileNameMillis
Like createFileName but the time now also includes milliseconds.- Parameters:
fileStartTime
-prefix
-fileType
-- Returns:
-
getUnpunctuatedDate
- Returns:
- a date string in a very compressed format (suitable for file names)
-
setViewTimes
public static void setViewTimes(long start, long end) -
getViewEndTime
public static long getViewEndTime() -
getViewPosition
public static long getViewPosition() -
setViewPosition
public static void setViewPosition(long viewPosition) -
millistoDateNum
public static double millistoDateNum(long timeMillis) Convert millis to MATLAB datenum.- Parameters:
timeMillis
- - Java datetime millis- Returns:
- MATLAB datenum.
-
dateNumtoMillis
public static long dateNumtoMillis(double datenum) Convert MATLAB datenum to millis;- Parameters:
MATLAB
- datenum- Returns:
- timeMillis equivalent of the MATLAB datenum.
-
millisToUnixEpoch
public static long millisToUnixEpoch(long millis) Convert to Unix Epoch. This is used by R.- Parameters:
millis
- - Java datetime millis
-
millistoExcelSerial
public static double millistoExcelSerial(long timeMillis) Converts millis to an excel serial data based on the Jan 1900 system.- Parameters:
timeMillis
-- Returns:
- excel serial datenum.
-
excelSerialtoMillis
public static long excelSerialtoMillis(double excelSerial) Converts excel Serial date number (Jan 1900 format) to millis.- Parameters:
excelSerial
- datenum- Returns:
- timeMillis equivalent of the excel datenum.
-
msFromDate
public static long msFromDate(int year, int month, int day, int hour, int minute, int second, int millis) Convert date values to millisecond time- Parameters:
dateString
-- Returns:
- time in milliseconds
-
readTimeDuration
Read the duration and convert back to millis.- Parameters:
duration
- - string representation of duration. Can be complete gobbly gook if inputed by user.- Returns:
- the datenum of the duration in millis.
-
setTimeCorrection
public static void setTimeCorrection(long correction) Set a time correction to add to all calls to gettimemillis();- Parameters:
correction
- time correction in millis.
-
getTimeCorrection
public static long getTimeCorrection()Get a time correction added to all calls to gettimemillis();- Returns:
- time correction in millis.
-