Beispiel #1
0
        private static string ConvertTimestampToString(int timestamp)
        {
            LogicGregDate gregDate = new LogicGregDate(timestamp / 86400);

            return(string.Format("{0:D4}{1:D2}{2:D2}T{3:D2}{4:D2}{5:D2}.000Z", gregDate.GetYear(), gregDate.GetMonth(), gregDate.GetDay(),
                                 timestamp % 86400 / 3600,
                                 timestamp % 86400 % 3600 / 60,
                                 timestamp % 86400 % 3600 % 60));
        }
Beispiel #2
0
        private static int ConvertStringToTimestamp(string time, bool round)
        {
            int spliter = time.IndexOf("T");

            Debugger.DoAssert(spliter == 8, "Unable to convert time. ISO8601 expected.");
            LogicGregDate date = new LogicGregDate(LogicStringUtil.ConvertToInt(time, 0, 4),
                                                   LogicStringUtil.ConvertToInt(time, 4, 6),
                                                   LogicStringUtil.ConvertToInt(time, 6, 8));

            date.Validate();

            int    totalSecs = date.GetIndex() * 86400;
            string dayTime   = time.Substring(spliter + 1);

            if (dayTime.Length < 2)
            {
                if (round)
                {
                    return(totalSecs + 82800);
                }

                return(totalSecs);
            }

            totalSecs += 3600 * LogicStringUtil.ConvertToInt(dayTime, 0, 2);

            if (dayTime.Length < 4)
            {
                if (round)
                {
                    return(totalSecs + 3540);
                }

                return(totalSecs);
            }

            totalSecs += 60 * LogicStringUtil.ConvertToInt(dayTime, 2, 4);

            if (dayTime.Length < 6)
            {
                if (round)
                {
                    return(totalSecs + 59);
                }

                return(totalSecs);
            }

            return(totalSecs + LogicStringUtil.ConvertToInt(dayTime, 4, 6));
        }