System.DateTimeParse.DetermineTimeZoneAdjustments C# (CSharp) Method

DetermineTimeZoneAdjustments() private static method

private static DetermineTimeZoneAdjustments ( DateTimeResult &result, DateTimeStyles styles, Boolean bTimeOnly ) : Boolean
result DateTimeResult
styles DateTimeStyles
bTimeOnly Boolean
return Boolean
        private static Boolean DetermineTimeZoneAdjustments(ref DateTimeResult result, DateTimeStyles styles, Boolean bTimeOnly) {

            // The flags AssumeUniveral and AssumeLocal only apply when the input does not have a time zone
            if ((result.flags & ParseFlags.TimeZoneUsed) == 0) {

                // If AssumeLocal or AssumeLocal is used, there will always be a kind specified. As in the
                // case when a time zone is present, it will default to being local unless AdjustToUniversal
                // is present. These comparisons determine whether setting the kind is sufficient, or if a
                // time zone adjustment is required. For consistentcy with the rest of parsing, it is desirable
                // to fall through to the Adjust methods below, so that there is consist handling of boundary
                // cases like wrapping around on time-only dates and temporarily allowing an adjusted date
                // to exceed DateTime.MaxValue
                if ((styles & DateTimeStyles.AssumeLocal) != 0) {
                    if ((styles & DateTimeStyles.AdjustToUniversal) != 0) {
                        result.flags |= ParseFlags.TimeZoneUsed;
                        result.timeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(result.parsedDate);
                    }
                    else {
                        result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Local);
                        return true;
                    }
                }
                else if ((styles & DateTimeStyles.AssumeUniversal) != 0) {
                    if ((styles & DateTimeStyles.AdjustToUniversal) != 0) {
                        result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
                        return true;
                    }
                    else {
                        result.flags |= ParseFlags.TimeZoneUsed;
                        result.timeZoneOffset = TimeSpan.Zero;
                    }
                }
                else {
                    // No time zone and no Assume flags, so DateTimeKind.Unspecified is fine
                    BCLDebug.Assert(result.parsedDate.Kind == DateTimeKind.Unspecified, "result.parsedDate.Kind == DateTimeKind.Unspecified");
                    return true;
                }
            }

            if (((styles & DateTimeStyles.RoundtripKind) != 0) && ((result.flags & ParseFlags.TimeZoneUtc) != 0)) {
                result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
                return true;
            }

            if ((styles & DateTimeStyles.AdjustToUniversal) != 0) {
                return (AdjustTimeZoneToUniversal(ref result));
            }
            return (AdjustTimeZoneToLocal(ref result, bTimeOnly));
        }