Class SQTime

java.lang.Object
com.strategyquant.lib.SQTime

public class SQTime extends Object
The Class SQTime.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 times
    static 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
    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
    toString​(long datetime, String dtf)
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • Log

      public static final org.slf4j.Logger Log
      The Constant Log.
    • DAY_MILLIS

      public static final long DAY_MILLIS
      The Constant DAY_MILLIS.
      See Also:
      Constant Field Values
    • MONDAY

      public static final int MONDAY
      The Constant MONDAY.
      See Also:
      Constant Field Values
    • TUESDAY

      public static final int TUESDAY
      The Constant TUESDAY.
      See Also:
      Constant Field Values
    • WEDNESDAY

      public static final int WEDNESDAY
      The Constant WEDNESDAY.
      See Also:
      Constant Field Values
    • THURSDAY

      public static final int THURSDAY
      The Constant THURSDAY.
      See Also:
      Constant Field Values
    • FRIDAY

      public static final int FRIDAY
      The Constant FRIDAY.
      See Also:
      Constant Field Values
    • SATURDAY

      public static final int SATURDAY
      The Constant SATURDAY.
      See Also:
      Constant Field Values
    • SUNDAY

      public static final int SUNDAY
      The Constant SUNDAY.
      See Also:
      Constant Field Values
    • shortDateFormat

      public static String shortDateFormat
      The short date format.
    • longDateFormat

      public static String 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 datetime
      value - the value
      Returns:
      the long
    • setHour

      public static long setHour(long datetime, int value)
      Sets the hour.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setDayOfWeek

      public static long setDayOfWeek(long datetime, int value)
      Sets the day of week.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setFirstDayOfWeek

      public static long setFirstDayOfWeek(long datetime)
      Sets the first day of week.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setDayOfMonth

      public static long setDayOfMonth(long datetime, int value)
      Sets the day of month.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setMonthOfYear

      public static long setMonthOfYear(long datetime, int value)
      Sets the month of year.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setSecond

      public static long setSecond(long datetime, int value)
      Sets the second.
      Parameters:
      datetime - the datetime
      value - the value
      Returns:
      the long
    • setTime

      public static long setTime(long datetime, int hour, int minute, int second)
      Sets the time.
      Parameters:
      datetime - the datetime
      hour - the hour
      minute - the minute
      second - 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 datetime
      hour - the hour
      minute - the minute
      second - the second
      miliseconds - the miliseconds
      Returns:
      the long
    • add

      public static long add(long datetime, int field, int amount)
      Adds the.
      Parameters:
      datetime - the datetime
      field - the field
      amount - the amount
      Returns:
      the long
    • minus

      public static long minus(long datetime, int field, int amount)
      Minus.
      Parameters:
      datetime - the datetime
      field - the field
      amount - the amount
      Returns:
      the long
    • addYears

      public static long addYears(long datetime, int year)
      Adds the years.
      Parameters:
      datetime - the datetime
      year - the year
      Returns:
      the long
    • addMonths

      public static long addMonths(long datetime, int months)
      Adds the months.
      Parameters:
      datetime - the datetime
      months - the months
      Returns:
      the long
    • addWeeks

      public static long addWeeks(long datetime, int weeks)
      Adds the weeks.
      Parameters:
      datetime - the datetime
      weeks - the weeks
      Returns:
      the long
    • addDays

      public static long addDays(long datetime, int day)
      Adds the days.
      Parameters:
      datetime - the datetime
      day - the day
      Returns:
      the long
    • addHours

      public static long addHours(long datetime, int hours)
      Adds the hours.
      Parameters:
      datetime - the datetime
      hours - the hours
      Returns:
      the long
    • addMinutes

      public static long addMinutes(long datetime, int minutes)
      Adds the minutes.
      Parameters:
      datetime - the datetime
      minutes - the minutes
      Returns:
      the long
    • addSeconds

      public static long addSeconds(long datetime, int seconds)
      Adds the seconds.
      Parameters:
      datetime - the datetime
      seconds - the seconds
      Returns:
      the long
    • toString

      public static String toString(long datetime, String dtf)
      To string.
      Parameters:
      datetime - the datetime
      dtf - the dtf
      Returns:
      the string
    • toString

      public static String toString(long datetime, org.joda.time.format.DateTimeFormatter formatter)
      To string.
      Parameters:
      datetime - the datetime
      formatter - the formatter
      Returns:
      the string
    • toDateString

      public static String toDateString(long datetime)
      To date string.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • toDateMinuteString

      public static String toDateMinuteString(long datetime)
      To date minute string.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • toFullDateMinuteString

      public static String toFullDateMinuteString(long datetime)
      To full date minute string.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • toFullDateTimeString

      public static String toFullDateTimeString(long datetime)
      To full date time string.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • toFullTime

      public static String toFullTime(long datetime)
      To full time.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • parseDateToMilis

      public static long parseDateToMilis(String strDateTime) throws ParseException
      Parses the date to milis.
      Parameters:
      strDateTime - the str date time
      Returns:
      the long
      Throws:
      ParseException - the parse exception
    • parseToMilis

      public static long parseToMilis(String strDateTime, String pattern)
      Parses the to milis.
      Parameters:
      strDateTime - the str date time
      pattern - the pattern
      Returns:
      the long
    • formatDate

      public static String formatDate(long datetime)
      Format date.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • formatDate

      public static String formatDate(long datetime, org.joda.time.format.DateTimeFormatter formater)
      Format date.
      Parameters:
      datetime - the datetime
      formater - the formater
      Returns:
      the string
    • formatDateQuick

      public static String formatDateQuick(long datetime)
      Format date quick.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • formatTime

      public static String formatTime(long datetime)
      Format time.
      Parameters:
      datetime - the datetime
      Returns:
      the string
    • toDate

      public static Date toDate(long datetime)
      To date.
      Parameters:
      datetime - the datetime
      Returns:
      the date
    • toTime

      public static Date toTime(long datetime)
      To time.
      Parameters:
      datetime - the datetime
      Returns:
      the date
    • formatDateTime

      public static String formatDateTime(long s)
      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

      public static String dowToString(int dow)
      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 1
      time2 - the time 2
      Returns:
      true, if successful
    • getMinutesBetween

      public static int getMinutesBetween(long msFrom, long msTo)
      Gets the minutes between.
      Parameters:
      msFrom - the ms from
      msTo - the ms to
      Returns:
      the minutes between
    • getDaysBetween

      public static int getDaysBetween(long msFrom, long msTo)
      Gets the days between.
      Parameters:
      msFrom - the ms from
      msTo - the ms to
      Returns:
      the days between
    • getWeeksBetween

      public static int getWeeksBetween(long msFrom, long msTo)
      Gets the weeks between.
      Parameters:
      msFrom - the ms from
      msTo - the ms to
      Returns:
      the months between
    • getMonthsBetween

      public static int getMonthsBetween(long msFrom, long msTo)
      Gets the months between.
      Parameters:
      msFrom - the ms from
      msTo - the ms to
      Returns:
      the months between
    • getYearsBetween

      public static int getYearsBetween(long startDate, long endDate)
      Gets the years between.
      Parameters:
      startDate - the start date
      endDate - 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 datetime
      time - the time
      Returns:
      the long
    • getTSDiffInMinutes

      public static int getTSDiffInMinutes(int time1, int time2)
      Gets the TS diff in minutes.
      Parameters:
      time1 - the time 1
      time2 - 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 year
      month - the month
      day - 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 year
      month - the month
      day - the day
      hour - the hour
      minute - the minute
      second - 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 datetime
      hhmm - the hhmm
      Returns:
      the long
    • toHHMMString

      public static String toHHMMString(long time)
      To HHMM string.
      Parameters:
      time - the time
      Returns:
      the string
    • getLogTime

      public static String getLogTime(boolean includingDate, boolean includingMillis)
      Gets the log time.
      Parameters:
      includingDate - the including date
      includingMillis - 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

      public static String toString(long time)
      To string.
      Parameters:
      time - the time
      Returns:
      the string
    • toUIDateString

      public static String toUIDateString(long time)
      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

      public static String getDurationText(long duration)