Package com.strategyquant.lib
Class SQTime
java.lang.Object
com.strategyquant.lib.SQTime
The Class SQTime.
-
Field Summary
Modifier and TypeFieldDescriptionstatic long
The Constant DAY_MILLIS.static int
The Constant FRIDAY.static org.slf4j.Logger
The Constant Log.static String
The long date format.static int
The Constant MONDAY.static int
The Constant SATURDAY.static String
The short date format.static int
The Constant SUNDAY.static int
The Constant THURSDAY.static int
The Constant TUESDAY.static int
The Constant WEDNESDAY. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
add(long datetime, int field, int amount)
Adds the.static long
addDays(long datetime, int day)
Adds the days.static long
addHours(long datetime, int hours)
Adds the hours.static long
addMinutes(long datetime, int minutes)
Adds the minutes.static long
addMonths(long datetime, int months)
Adds the months.static long
addSeconds(long datetime, int seconds)
Adds the seconds.static long
addWeeks(long datetime, int weeks)
Adds the weeks.static long
addYears(long datetime, int year)
Adds the years.static long
correctDayEnd(long date)
Correct day end.static long
correctDayEndMT(long date)
Correct day end MT.static long
correctDayStart(long date)
Correct day start.static int
dowToMetatrader(int dow)
Dow to metatrader.static String
dowToString(int dow)
Dow to string.static String
formatDate(long datetime)
Format date.static String
formatDate(long datetime, org.joda.time.format.DateTimeFormatter formater)
Format date.static String
formatDateQuick(long datetime)
Format date quick.static String
formatDateTime(long s)
Format date time.static String
formatTime(long datetime)
Format time.static long
getDateInMs(long datetime)
Gets the date in ms.static int
getDateTime(long datetime)
Gets the date time.static int
getDay(long datetime)
Gets the day.static int
getDayOfWeek(long datetime)
Gets the day of week.static int
getDayOfWeekOriginal(long datetime)
Gets the day of week original.static int
getDayOfYear(long datetime)
Gets the day of year.static int
getDaysBetween(long msFrom, long msTo)
Gets the days between.static int
getDaysInMonth(long datetime)
Gets the days in month.static int
getDiffInDays(long time1, long time2)
Returns difference in calendar days between two timesstatic String
getDurationText(long duration)
static int
getFullYear(long datetime)
Gets the full year.static int
getHHMM(long time)
Gets the hhmm.static int
getHour(long datetime)
Gets the hour.static long
Gets the local current time in milliseconds.static String
getLogTime(boolean includingDate, boolean includingMillis)
Gets the log time.static long
getMilis(long datetime)
Gets the milis.static int
getMiliSecond(long datetime)
Gets the mili second.static int
getMinute(long datetime)
Gets the minute.static int
getMinutesBetween(long msFrom, long msTo)
Gets the minutes between.static int
getMonth(long datetime)
Gets the month.static int
getMonthOriginal(long datetime)
Gets the month original.static int
getMonthsBetween(long msFrom, long msTo)
Gets the months between.static int
getSecond(long datetime)
Gets the second.static int
getTimeAsTSTime(long datetime)
Gets the time as TS time.static int
getTSDiffInMinutes(int time1, int time2)
Gets the TS diff in minutes.static int
getWeekOfYear(long datetime)
Gets the week of year.static int
getWeeksBetween(long msFrom, long msTo)
Gets the weeks between.static int
getYear(long datetime)
Gets the year.static int
getYearsBetween(long startDate, long endDate)
Gets the years between.static int
HHMMToMinutes(int value)
HHMM to minutes.static void
init()
Inits the.static long
minus(long datetime, int field, int amount)
Minus.static int
minutesToHHMM(int value)
Minutes to HHMM.static long
parseDateToMilis(String strDateTime)
Parses the date to milis.static long
parseToMilis(String strDateTime, String pattern)
Parses the to milis.static long
setDayOfMonth(long datetime, int value)
Sets the day of month.static long
setDayOfWeek(long datetime, int value)
Sets the day of week.static long
setFirstDayOfWeek(long datetime)
Sets the first day of week.static long
setHHMM(long datetime, int hhmm)
Sets the HHMM.static long
setHour(long datetime, int value)
Sets the hour.static long
setMiliSeconds(long datetime, int millis)
Sets the miliseconds.static long
setMinute(long datetime, int value)
Sets the minute.static long
setMonthOfYear(long datetime, int value)
Sets the month of year.static long
setSecond(long datetime, int value)
Sets the second.static long
setTime(long datetime, int hour, int minute, int second)
Sets the time.static long
setTime(long datetime, int hour, int minute, int second, int miliseconds)
Sets the time.static long
setTimeToTSTime(long datetime, int time)
Sets the time to TS time.static boolean
timesInSameMinute(int time1, int time2)
Times in same minute.static Date
toDate(long datetime)
To date.static String
toDateMinuteString(long datetime)
To date minute string.static String
toDateString(long datetime)
To date string.static String
toFullDateMinuteString(long datetime)
To full date minute string.static String
toFullDateTimeString(long datetime)
To full date time string.static String
toFullTime(long datetime)
To full time.static String
toHHMMString(long time)
To HHMM string.static long
toHours(long time)
To hours.static long
toLong(int year, int month, int day)
To long.static long
toLong(int year, int month, int day, int hour, int minute, int second)
To long.static int
toNumberTime(long datetime)
To number time.static String
toString(long time)
To string.static String
To string.static String
toString(long datetime, org.joda.time.format.DateTimeFormatter formatter)
To string.static Date
toTime(long datetime)
To time.static String
toUIDateString(long time)
To UI date string.
-
Field Details
-
Log
public static final org.slf4j.Logger LogThe Constant Log. -
DAY_MILLIS
public static final long DAY_MILLISThe Constant DAY_MILLIS.- See Also:
- Constant Field Values
-
MONDAY
public static final int MONDAYThe Constant MONDAY.- See Also:
- Constant Field Values
-
TUESDAY
public static final int TUESDAYThe Constant TUESDAY.- See Also:
- Constant Field Values
-
WEDNESDAY
public static final int WEDNESDAYThe Constant WEDNESDAY.- See Also:
- Constant Field Values
-
THURSDAY
public static final int THURSDAYThe Constant THURSDAY.- See Also:
- Constant Field Values
-
FRIDAY
public static final int FRIDAYThe Constant FRIDAY.- See Also:
- Constant Field Values
-
SATURDAY
public static final int SATURDAYThe Constant SATURDAY.- See Also:
- Constant Field Values
-
SUNDAY
public static final int SUNDAYThe Constant SUNDAY.- See Also:
- Constant Field Values
-
shortDateFormat
The short date format. -
longDateFormat
The long date format.
-
-
Constructor Details
-
SQTime
public SQTime()
-
-
Method Details
-
init
public static void init()Inits the. -
getDateTime
public static int getDateTime(long datetime)Gets the date time.- Parameters:
datetime
- the datetime- Returns:
- the date time
-
getDateInMs
public static long getDateInMs(long datetime)Gets the date in ms. without hour, minute, second, milisecond part- Returns:
- the date in ms
-
getYear
public static int getYear(long datetime)Gets the year.- Parameters:
datetime
- the datetime- Returns:
- the year
-
getFullYear
public static int getFullYear(long datetime)Gets the full year.- Parameters:
datetime
- the datetime- Returns:
- the full year
-
getMonthOriginal
public static int getMonthOriginal(long datetime)Gets the month original.- Parameters:
datetime
- the datetime- Returns:
- the month original
-
getMonth
public static int getMonth(long datetime)Gets the month.- Parameters:
datetime
- the datetime- Returns:
- the month
-
getDayOfWeekOriginal
public static int getDayOfWeekOriginal(long datetime)Gets the day of week original.- Parameters:
datetime
- the datetime- Returns:
- the day of week original
-
getDayOfWeek
public static int getDayOfWeek(long datetime)Gets the day of week.- Parameters:
datetime
- the datetime- Returns:
- the day of week
-
getDay
public static int getDay(long datetime)Gets the day.- Parameters:
datetime
- the datetime- Returns:
- the day
-
getDaysInMonth
public static int getDaysInMonth(long datetime)Gets the days in month.- Parameters:
datetime
- the datetime- Returns:
- the days in month
-
getDayOfYear
public static int getDayOfYear(long datetime)Gets the day of year.- Parameters:
datetime
- the datetime- Returns:
- the day of year
-
getWeekOfYear
public static int getWeekOfYear(long datetime)Gets the week of year.- Parameters:
datetime
- the datetime- Returns:
- the week of year
-
getHour
public static int getHour(long datetime)Gets the hour.- Parameters:
datetime
- the datetime- Returns:
- the hour
-
getMinute
public static int getMinute(long datetime)Gets the minute.- Parameters:
datetime
- the datetime- Returns:
- the minute
-
getSecond
public static int getSecond(long datetime)Gets the second.- Parameters:
datetime
- the datetime- Returns:
- the second
-
getMiliSecond
public static int getMiliSecond(long datetime)Gets the mili second.- Parameters:
datetime
- the datetime- Returns:
- the mili second
-
setMinute
public static long setMinute(long datetime, int value)Sets the minute.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setHour
public static long setHour(long datetime, int value)Sets the hour.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setDayOfWeek
public static long setDayOfWeek(long datetime, int value)Sets the day of week.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setFirstDayOfWeek
public static long setFirstDayOfWeek(long datetime)Sets the first day of week.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setDayOfMonth
public static long setDayOfMonth(long datetime, int value)Sets the day of month.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setMonthOfYear
public static long setMonthOfYear(long datetime, int value)Sets the month of year.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setSecond
public static long setSecond(long datetime, int value)Sets the second.- Parameters:
datetime
- the datetimevalue
- the value- Returns:
- the long
-
setTime
public static long setTime(long datetime, int hour, int minute, int second)Sets the time.- Parameters:
datetime
- the datetimehour
- the hourminute
- the minutesecond
- the second- Returns:
- the long
-
setTime
public static long setTime(long datetime, int hour, int minute, int second, int miliseconds)Sets the time.- Parameters:
datetime
- the datetimehour
- the hourminute
- the minutesecond
- the secondmiliseconds
- the miliseconds- Returns:
- the long
-
add
public static long add(long datetime, int field, int amount)Adds the.- Parameters:
datetime
- the datetimefield
- the fieldamount
- the amount- Returns:
- the long
-
minus
public static long minus(long datetime, int field, int amount)Minus.- Parameters:
datetime
- the datetimefield
- the fieldamount
- the amount- Returns:
- the long
-
addYears
public static long addYears(long datetime, int year)Adds the years.- Parameters:
datetime
- the datetimeyear
- the year- Returns:
- the long
-
addMonths
public static long addMonths(long datetime, int months)Adds the months.- Parameters:
datetime
- the datetimemonths
- the months- Returns:
- the long
-
addWeeks
public static long addWeeks(long datetime, int weeks)Adds the weeks.- Parameters:
datetime
- the datetimeweeks
- the weeks- Returns:
- the long
-
addDays
public static long addDays(long datetime, int day)Adds the days.- Parameters:
datetime
- the datetimeday
- the day- Returns:
- the long
-
addHours
public static long addHours(long datetime, int hours)Adds the hours.- Parameters:
datetime
- the datetimehours
- the hours- Returns:
- the long
-
addMinutes
public static long addMinutes(long datetime, int minutes)Adds the minutes.- Parameters:
datetime
- the datetimeminutes
- the minutes- Returns:
- the long
-
addSeconds
public static long addSeconds(long datetime, int seconds)Adds the seconds.- Parameters:
datetime
- the datetimeseconds
- the seconds- Returns:
- the long
-
toString
To string.- Parameters:
datetime
- the datetimedtf
- the dtf- Returns:
- the string
-
toString
To string.- Parameters:
datetime
- the datetimeformatter
- the formatter- Returns:
- the string
-
toDateString
To date string.- Parameters:
datetime
- the datetime- Returns:
- the string
-
toDateMinuteString
To date minute string.- Parameters:
datetime
- the datetime- Returns:
- the string
-
toFullDateMinuteString
To full date minute string.- Parameters:
datetime
- the datetime- Returns:
- the string
-
toFullDateTimeString
To full date time string.- Parameters:
datetime
- the datetime- Returns:
- the string
-
toFullTime
To full time.- Parameters:
datetime
- the datetime- Returns:
- the string
-
parseDateToMilis
Parses the date to milis.- Parameters:
strDateTime
- the str date time- Returns:
- the long
- Throws:
ParseException
- the parse exception
-
parseToMilis
Parses the to milis.- Parameters:
strDateTime
- the str date timepattern
- the pattern- Returns:
- the long
-
formatDate
Format date.- Parameters:
datetime
- the datetime- Returns:
- the string
-
formatDate
Format date.- Parameters:
datetime
- the datetimeformater
- the formater- Returns:
- the string
-
formatDateQuick
Format date quick.- Parameters:
datetime
- the datetime- Returns:
- the string
-
formatTime
Format time.- Parameters:
datetime
- the datetime- Returns:
- the string
-
toDate
To date.- Parameters:
datetime
- the datetime- Returns:
- the date
-
toTime
To time.- Parameters:
datetime
- the datetime- Returns:
- the date
-
formatDateTime
Format date time.- Parameters:
s
- the seconds- Returns:
- the string
-
dowToMetatrader
public static int dowToMetatrader(int dow)Dow to metatrader.- Parameters:
dow
- the dow- Returns:
- the int
-
dowToString
Dow to string.- Parameters:
dow
- the dow- Returns:
- the string
-
timesInSameMinute
public static boolean timesInSameMinute(int time1, int time2)Times in same minute.- Parameters:
time1
- the time 1time2
- the time 2- Returns:
- true, if successful
-
getMinutesBetween
public static int getMinutesBetween(long msFrom, long msTo)Gets the minutes between.- Parameters:
msFrom
- the ms frommsTo
- the ms to- Returns:
- the minutes between
-
getDaysBetween
public static int getDaysBetween(long msFrom, long msTo)Gets the days between.- Parameters:
msFrom
- the ms frommsTo
- the ms to- Returns:
- the days between
-
getWeeksBetween
public static int getWeeksBetween(long msFrom, long msTo)Gets the weeks between.- Parameters:
msFrom
- the ms frommsTo
- the ms to- Returns:
- the months between
-
getMonthsBetween
public static int getMonthsBetween(long msFrom, long msTo)Gets the months between.- Parameters:
msFrom
- the ms frommsTo
- the ms to- Returns:
- the months between
-
getYearsBetween
public static int getYearsBetween(long startDate, long endDate)Gets the years between.- Parameters:
startDate
- the start dateendDate
- the end date- Returns:
- the years between
-
toNumberTime
public static int toNumberTime(long datetime)To number time.- Parameters:
datetime
- the datetime- Returns:
- the int
-
setMiliSeconds
public static long setMiliSeconds(long datetime, int millis)Sets the miliseconds.- Returns:
- the milis
-
getMilis
public static long getMilis(long datetime)Gets the milis.- Parameters:
datetime
- the datetime- Returns:
- the milis
-
getTimeAsTSTime
public static int getTimeAsTSTime(long datetime)Gets the time as TS time.- Parameters:
datetime
- the datetime- Returns:
- the time as TS time
-
setTimeToTSTime
public static long setTimeToTSTime(long datetime, int time)Sets the time to TS time.- Parameters:
datetime
- the datetimetime
- the time- Returns:
- the long
-
getTSDiffInMinutes
public static int getTSDiffInMinutes(int time1, int time2)Gets the TS diff in minutes.- Parameters:
time1
- the time 1time2
- the time 2- Returns:
- the TS diff in minutes
-
toLong
public static long toLong(int year, int month, int day)To long.- Parameters:
year
- the yearmonth
- the monthday
- the day- Returns:
- the long
-
toLong
public static long toLong(int year, int month, int day, int hour, int minute, int second)To long.- Parameters:
year
- the yearmonth
- the monthday
- the dayhour
- the hourminute
- the minutesecond
- the second- Returns:
- the long
-
correctDayEnd
public static long correctDayEnd(long date)Correct day end.- Parameters:
date
- the date- Returns:
- the long
-
correctDayEndMT
public static long correctDayEndMT(long date)Correct day end MT.- Parameters:
date
- the date- Returns:
- the long
-
correctDayStart
public static long correctDayStart(long date)Correct day start.- Parameters:
date
- the date- Returns:
- the long
-
setHHMM
public static long setHHMM(long datetime, int hhmm)Sets the HHMM.- Parameters:
datetime
- the datetimehhmm
- the hhmm- Returns:
- the long
-
toHHMMString
To HHMM string.- Parameters:
time
- the time- Returns:
- the string
-
getLogTime
Gets the log time.- Parameters:
includingDate
- the including dateincludingMillis
- the including millis- Returns:
- the log time
-
getLocalCurrentTimeInMs
public static long getLocalCurrentTimeInMs()Gets the local current time in milliseconds.- Returns:
- the log time
-
toHours
public static long toHours(long time)To hours.- Parameters:
time
- the time- Returns:
- the long
-
toString
To string.- Parameters:
time
- the time- Returns:
- the string
-
toUIDateString
To UI date string.- Parameters:
time
- the time- Returns:
- the string
-
getHHMM
public static int getHHMM(long time)Gets the hhmm.- Parameters:
time
- the time- Returns:
- the hhmm
-
minutesToHHMM
public static int minutesToHHMM(int value)Minutes to HHMM.- Parameters:
value
- the value- Returns:
- the int
-
HHMMToMinutes
public static int HHMMToMinutes(int value)HHMM to minutes.- Parameters:
value
- the value- Returns:
- the int
-
getDiffInDays
public static int getDiffInDays(long time1, long time2)Returns difference in calendar days between two times- Parameters:
time1
-time2
-- Returns:
-
getDurationText
-