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
Fields - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateFileName(long fileStartTime, String prefix, String fileType) Creates a file name containing the time and a user defined prefix and file endstatic StringcreateFileName(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other informationstatic StringcreateFileName(String directory, String prefix, String fileType) Create a file name that doesn't contain a timestatic StringcreateFileNameMillis(long fileStartTime, String prefix, String fileType) Like createFileName but the time now also includes milliseconds.static StringcreateFileNameMillis(long fileStartTime, String directory, String prefix, String fileType) Create a file name based on a time and other informationstatic DatedateFromDateString(String dateString, boolean useLocal) Read a date string and turn it into a Datestatic longdateNumtoMillis(double datenum) Convert MATLAB datenum to millis;static longexcelSerialtoMillis(double excelSerial) Converts excel Serial date number (Jan 1900 format) to millis.static StringformatCompactDate(long timeMillis, boolean useLocal) Format date in format "yyyyMMdd" using GMT as the time zonestatic StringformatDate(long timeInMillis) Format the data in the dd MMMM yyyy formatstatic StringformatDate(long timeInMillis, boolean useLocal) Format the data in the dd MMMM yyyy formatstatic StringformatDate2(long timeInMillis, boolean useLocal) Format the data in the yyMMdd formatstatic StringformatDateTime(long timeInMillis) Formats the time and data in a long formatstatic StringformatDateTime(long timeInMillis, boolean useLocal) Formats the time and data in a long formatstatic StringformatDateTime(Date date) static StringformatDateTime(Date date, boolean useLocal) Get a formatted date and time string.static StringformatDateTime2(long timeInMillis) Formats the time and data in a long format but without the GMT label at the end.static StringformatDateTime2(long timeInMillis, boolean useLocal) Formats the time and data in a long format but without the GMT label at the end.static StringformatDateTime2(long timeInMillis, String format, boolean useLocal) Formats the time and data in a long format but without the GMT label at the end.static StringformatDBDate(long timeInMillis) Formats the date and time in the correct format for database output.static StringformatDBDateTime(long timeInMillis) Formats the date and time in the correct format for database output.static StringformatDBDateTime(long timeInMillis, boolean showMillis) Formats the date and time in the correct format for database output.static StringformatDBStyleTime(long timeInMillis, boolean showMillis, boolean useLocal) static StringformatDuration(long timeInMillis) Format a time in milliseconds as a number of days / seconds, etc.static StringformatDuration(long timeInMillis, String middleString) static StringformatDuration(long timeInMillis, String middleString1, String middleString2) static StringformatFileDate(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 StringformatFileDate(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 StringformatFileDateTime(long timeMillis, boolean useLocal) Format date and time in format "yyyyMMdd_HHmmss"static StringformatLocalDateTime(long timeInMillis) Formats the local time and data in a long formatstatic StringformatLocalDateTime(Date date) Get a formatted local date and time string.static StringformatLocalDateTime2(long timeInMillis) Formats the local time and date in a long format - identical to formatDateTime2(long), but using the local-PC time zonestatic StringformatLocalDateTime2(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 StringformatLocalDBDateTime(long timeInMillis) Formats the date and time in the correct format for database output but in local time.static StringformatLocalFileDateTime(long timeMillis) Format date and time in format "yyyyMMdd_HHmmss", but using the local pc time zonestatic StringformatLocalTime(long timeMillis, boolean showMillis) Format a time string optionally showing the milliseconds with a given precision for UTC time zonestatic StringformatTime(long timeMillis) Format a time string in the format HH:MM:SSstatic StringformatTime(long timeMillis, boolean showMills) Format a time string in the format HH:MM:SSstatic StringformatTime(long timeMillis, boolean showMillis, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision for UTC time zonestatic StringformatTime(long timeMillis, int millisDigits) Format a time string optionally showing the milliseconds with a given precision.static StringformatTime(long timeMillis, int millisDigits, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision.static StringformatTime2(long timeMillis, int millisDigits, boolean useLocal) Format a time string optionally showing the milliseconds with a given precision.static StringformatTodaysTime(long timeInMillis) static StringformatTodaysTime(long timeInMillis, boolean useLocal) static CalendarGet the current datestatic CalendargetCalendarDate(long timeInMillis) Get the date for a given timestatic StringgetDate()static TimeZonegetDisplayTimeZone(boolean useLocal) static longstatic longgetTime()a formatted time stringstatic longGet a time correction added to all calls to gettimemillis();static longIf files are being analysed, return the time based on the file position.static StringgetUnpunctuatedDate(boolean useLocal) static longstatic longstatic final booleanisSameDay(long t1, long t2) Compares two times in milliseconds to see if they are on the same day or not.static booleanstatic LongmillisFromDateString(String dateString, boolean useLocal) Convert a date string into a millisecond time.static longmillisFromDateTimeString(String dateTime, boolean stringInUTC) Return the time in milliseconds from the passed String sing the format "dd MMM yyyy HH:mm:ss"static longmillisFromDateTimeString(String dateTime, String format, boolean stringInUTC) Return the time in milliseconds from the passed String, using the passed formatstatic doublemillistoDateNum(long timeMillis) Convert millis to MATLAB datenum.static doublemillistoExcelSerial(long timeMillis) Converts millis to an excel serial data based on the Jan 1900 system.static longmillisToUnixEpoch(long millis) Convert to Unix Epoch.static longmsFromDate(int year, int month, int day, int hour, int minute, int second, int millis) Convert date values to millisecond timestatic longmsFromDateString(String dateString) Read a date string and turn it into a millisecond time.static longmsFromDateString(String dateString, boolean useLocal) Read a date string and turn it into a millisecond time.static longmsFromTimeString(String timeString) Read a time string and turn it into a millisecond time.static longmsFromTimeString(String timeString, boolean useLocal) Read a time string and turn it into a millisecond time.static LongreadTimeDuration(String duration) Read the duration and convert back to millis.static voidsetSessionStartTime(long sessionStartTime) static voidsetSessionStartTime(long sessionStartTime, long soundFileTimeMillis) static voidsetSoundFile(boolean soundFile) static voidsetSoundFileTimeInMillis(long soundFileTimeMillis) Relative time within a sound file.static voidsetTimeCorrection(long correction) Set a time correction to add to all calls to gettimemillis();static voidsetViewPosition(long viewPosition) static voidsetViewTimes(long start, long end) static DatetimeFromTimeString(String timeString, boolean useLocal) Read a time string and turn it into a Datestatic LongunpackStandardDateTime(String numstr) static DateunpackUnknownDateString(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 And also set the file time to zero within that since both this and setSoundFileTime send out notifications, so this can really mess up timing, causing new binary files to be created and all sorts of other problems.
 - 
setSessionStartTime
public static void setSessionStartTime(long sessionStartTime, long soundFileTimeMillis) - Parameters:
 sessionStartTime- the time that processing startedsoundFileTimeMillis- sound file time relative to start time. Good to set this zero right away.
 - 
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.
 
 
 -