Re: discussion about UTC/GMT, isDuring() and getFeasiblePosition

View: New views
1 Messages — Rating Filter:   Alert me  

Re: discussion about UTC/GMT, isDuring() and getFeasiblePosition

by Kirill Jacobson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

(moving this discussion from an email thread to the forum)

Hi Ulrich,

There is no such thing as UTC time zone in Java. Let's have a quick look at the TimeZone class. If a given zone id is not found in the lib/zi folder the code falls back and returns GMT. If you think that GMT sounds confusing lets use Etc/UTC instead. I attached a patch for either ways. Even better solution is a class org.activequant.core.Constants with project wide defaults (like TIMEZONE_UTC). I volunteer to crate a patch. What do you think?

Regards,
Kirill

aq-base-upgrade-to-GMT.patch
aq-base-upgrade-to-Etc-UTC.patch


Links related to this discussion:
FileNotFoundException-in-TimeStampFormat
www.quickfixj.org/jira/browse/QFJ-264

    /**
     * Gets the <code>TimeZone</code> for the given ID.
     *
     * @param ID the ID for a <code>TimeZone</code>, either an abbreviation
     * such as "PST", a full name such as "America/Los_Angeles", or a custom
     * ID such as "GMT-8:00". Note that the support of abbreviations is
     * for JDK 1.1.x compatibility only and full names should be used.
     *
     * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
     * cannot be understood.
     */
    public static synchronized TimeZone getTimeZone(String ID) {
        return getTimeZone(ID, true);
    }

    private static TimeZone getTimeZone(String ID, boolean fallback) {
        TimeZone tz = ZoneInfo.getTimeZone(ID);
        if (tz == null) {
            tz = parseCustomTimeZone(ID);
            if (tz == null && fallback) {
                tz = new ZoneInfo(GMT_ID, 0);
            }
        }
        return tz;
    }


Ulrich Staudinger-2 wrote:
Hi Kirill,

i had a look at your patch, point is, i cannot directly copy-paste it into TimeSeriesUtil which wouldn't be that tragic, but the use of the GMT TimeZone is too specific. Maybe switching to UTC would make things better ... Ideally, i can copy-paste a patch directly into the specific class.
For me it is ok to discuss these things on the mailing list. An isDuring(TS) function would be very handy ! Can you write that one ?

Thanks,
Ulrich


On Thu, Sep 24, 2009 at 5:45 PM, kirill.jacobson <...> wrote:

    Ulrich,

    It seems that getFeasibleTimeStampPosition () method doesn't work properly when an event time stamp

    a) is not equal to any candle time stamp in the series
    b) happens prior to the first candle's time stamp (eod) but within the interval covered by this candle (day)

    A repo case is attached to the BUG-21 (link).

    To fix the problem I added a function to the CandlestickChart class that returns position of the candle that covers the timestamp. If a candle is not found the series the function doesn't throw an exception but returns zero.

    I couldn't find a function that checks if a time stamp is covered by a candle. Should an isDuring(TimeStamp) function be added to the Candle class?

...
    Thank you,
    Kirill


        int getFeasibleTimeStampPosition(CandleSeries series, TimeStamp date) {
           
            ListIterator<Candle> iter = series.listIterator();
            while (iter.hasNext()) {
                Candle candle = iter.next();
               
                TimeStamp candleEnd = candle.getTimeStamp();
               
                if (candleEnd.isBefore(date))
                    return 0;
               
                if (candleEnd.isEqual(date))
                    return iter.nextIndex();
                   
                Calendar calendar = Calendar.getInstance(CalendarUtils.TIMEZONE_GMT);
                calendar.setTime(candleEnd.getDate());
                TimeStamp candleStart = new TimeStamp( candle.getTimeFrame().subtractFromCalendar(calendar).getTime() );
               
                if (candleStart.isBefore(date))
                    return iter.nextIndex();
            }
            // throw new ValueNotFoundException("Cannot find value for date '" + date + "'.");
            return 0;

        }