Symphony-DAS / symphony-matlab

Symphony Data Acquisition System
http://symphony-das.github.io
MIT License
19 stars 5 forks source link

Fix dateTimeOffsetFromDatetime for 'Europe/London' timezone #47

Closed cafarm closed 5 years ago

cafarm commented 5 years ago

The symphonyui.core.CoreObject.dateTimeOffsetFromDatetime method is currently broken when your timezone is 'Europe/London'. The below code includes the fix.

function dto = dateTimeOffsetFromDatetime(obj, t) %#ok<INUSL>
    if isempty(t.TimeZone)
        error('Datetime ''TimeZone'' must be set');
    end
    t.Format = 'ZZZZZ';
    tz = char(t);
    if tz(1) == '+'
        tz(1) = [];
    elseif strcmp(tz, 'Z')
        tz = '00:00';
    end
    offset = System.TimeSpan.Parse(tz);
    dto = System.DateTimeOffset(t.Year, t.Month, t.Day, t.Hour, t.Minute, floor(t.Second), round(1000*rem(t.Second, 1)), offset);
end