コード例 #1
0
        static long LocaltimeOffset(DateTime p, FuncContext fctx, out RC rc)
        {
            // Initialize the contents of sLocal to avoid a compiler warning.
            tm sLocal = new tm();

            DateTime x = p;
            ComputeYMD_HMS(x);
            if (x.Y < 1971 || x.Y >= 2038)
            {
                x.Y = 2000;
                x.M = 1;
                x.D = 1;
                x.h = 0;
                x.m = 0;
                x.s = 0.0;
            }
            else
            {
                int s = (int)(x.s + 0.5);
                x.s = s;
            }
            x.tz = 0;
            x.ValidJD = false;
            ComputeJD(x);
            time_t t = (long)(x.JD / 1000 - 210866760000L);
            if (OsLocaltime(t, sLocal) != 0)
            {
                Vdbe.Result_Error(fctx, "local time unavailable", -1);
                rc = RC.ERROR;
                return 0;
            }
            DateTime y = new DateTime();
            y.Y = sLocal.tm_year; // +1900;
            y.M = sLocal.tm_mon; // +1;
            y.D = sLocal.tm_mday;
            y.h = sLocal.tm_hour;
            y.m = sLocal.tm_min;
            y.s = sLocal.tm_sec;
            y.ValidYMD = true;
            y.ValidHMS = true;
            y.ValidJD = false;
            y.ValidTZ = false;
            ComputeJD(y);
            rc = RC.OK;
            return (int)(y.JD - x.JD);
        }