Esempio n. 1
0
        public static string GetStandardPattern(char format, DateTimeFormatInfo dfi, bool forDateTimeOffset, out bool useutc, out bool use_invariant, out bool needsTranslation)
        {
            String pattern;

            useutc = false;
            use_invariant = false;
            needsTranslation = true;

            switch (format)
            {
                case 'd':
                    if(dfi.ShortDatePattern != null)
                        pattern = dfi.ShortDatePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.SHORT, -1);
                        needsTranslation = false;
                    }
                    break;
                case 'D':
                    if (dfi.LongDatePattern != null)
                        pattern = dfi.LongDatePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.FULL, -1);
                        needsTranslation = false;
                    }
                    break;
                case 'f':
                    if (dfi.LongDatePattern != null && dfi.ShortTimePattern != null)
                        pattern = dfi.LongDatePattern + " " + dfi.ShortTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.FULL, DateFormat.SHORT);
                        needsTranslation = false;
                    }
                    break;
                case 'F':
                    if (dfi.FullDateTimePattern != null)
                        pattern = dfi.FullDateTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.FULL, DateFormat.MEDIUM);
                        needsTranslation = false;
                    }
                    break;
                case 'g':
                    if (dfi.ShortDatePattern != null && dfi.ShortTimePattern != null)
                        pattern = dfi.ShortDatePattern + " " + dfi.ShortTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.SHORT, DateFormat.SHORT);
                        needsTranslation = false;
                        
                    }
                    break;
                case 'G':
                    if (dfi.ShortDatePattern != null && dfi.LongTimePattern != null)
                        pattern = dfi.ShortDatePattern + " " + dfi.LongTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(DateFormat.SHORT, DateFormat.MEDIUM);
                        needsTranslation = false;
                        
                    }
                    break;
                case 'm':
                case 'M':
                    pattern = dfi.MonthDayPattern;
                    break;
                case 'o':
                case 'O':
                    pattern = dfi.RoundtripPattern;
                    use_invariant = true;
                    break;
                case 'r':
                case 'R':
                    pattern = dfi.RFC1123Pattern;
                    if (forDateTimeOffset)
                        useutc = true;
                    use_invariant = true;
                    break;
                case 's':
                    pattern = dfi.SortableDateTimePattern;
                    use_invariant = true;
                    break;
                case 't':
                    if (dfi.ShortTimePattern != null)
                        pattern = dfi.ShortTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(-1, DateFormat.SHORT);
                        needsTranslation = false;
                    }
                    break;
                case 'T':
                    if (dfi.LongTimePattern != null)
                        pattern = dfi.LongTimePattern;
                    else
                    {
                        pattern = dfi.GetJavaPattern(-1, DateFormat.MEDIUM);
                        needsTranslation = false;
                    }
                    break;
                case 'u':
                    pattern = dfi.UniversalSortableDateTimePattern;
                    if (forDateTimeOffset)
                        useutc = true;
                    use_invariant = true;
                    break;
                case 'U':
                    if (forDateTimeOffset)
                        pattern = null;
                    else
                    {
                        if (dfi.FullDateTimePattern != null)
                            pattern = dfi.FullDateTimePattern;
                        else
                        {
                            pattern = dfi.GetJavaPattern(DateFormat.FULL, DateFormat.MEDIUM);
                            needsTranslation = false;
                        }
                        useutc = true;
                    }
                    break;
                case 'y':
                case 'Y':
                    pattern = dfi.YearMonthPattern;
                    break;
                default:
                    pattern = null;
                    break;
            }

            return pattern;
        }