Пример #1
0
        public string GetDayPeriod(string type, LocaleFieldSize width,
                                   LocaleFieldType compose = LocaleFieldType.Default)
        {
            LdmlNode dayPeriods = this.Select("dayPeriods");

            var node = dayPeriods.Select(new NodePathEntry("dayPeriodContext", compose.ToCode()));

            NodePathEntry[] path =
            {
                new NodePathEntry("dayPeriodWidth", width.ToCode()),
                new NodePathEntry("dayPeriod",      type)
            };
            foreach (int w in XUtil.GetClosest((int)width, (int)LocaleFieldSize.Wide))
            {
                path[0].Attributes[0].Value = ((LocaleFieldSize)w).ToCode();

                var rNode = node.Select(path);
                if (rNode != null)
                {
                    return(rNode.Value);
                }
            }
            //if ( compose == EntryCompose.StandAlone ) {
            //    return GetDayPeriod( type, width );
            //}
            return(null);
        }
Пример #2
0
        public static IEnumerable<LocaleFieldPair> GetClosest( LocaleFieldType compose,
            LocaleFieldSize format ) {
            LocaleFieldSize initFormat = format;

            for( int i = 1; i < (int)_entryFormatMaxValue; i++ ) {
                LocaleFieldSize cformat = (LocaleFieldSize)( (int)initFormat + i );
                if( cformat <= _entryFormatMaxValue ) {
                    yield return new LocaleFieldPair( cformat, compose );
                }
                cformat = (LocaleFieldSize)( (int)initFormat - i );
                if( cformat > 0 ) {
                    yield return new LocaleFieldPair( cformat, compose );
                }
            }
            if( compose == LocaleFieldType.StandAlone ) {
                compose = LocaleFieldType.Default;
                yield return new LocaleFieldPair( initFormat, compose );

                for( int i = 1; i < (int)_entryFormatMaxValue; i++ ) {
                    LocaleFieldSize cformat = (LocaleFieldSize)( (int)initFormat + i );
                    if( cformat <= _entryFormatMaxValue ) {
                        yield return new LocaleFieldPair( cformat, compose );
                    }
                    cformat = (LocaleFieldSize)( (int)initFormat - i );
                    if( cformat > 0 ) {
                        yield return new LocaleFieldPair( cformat, compose );
                    }
                }
            }
        }
Пример #3
0
 //public DayPeriodRule[] GetDayPeriods( EntryFormat width, EntryCompose compose = EntryCompose.Default ) {
 //    var node = _root.Select( new NodePathEntry( "timeFormats" ),
 //        new NodePathEntry( "timeFormatLength", new LdmlAttributeValue( LdmlAttribute.Type, width.ToCode() ) )
 //        );
 //    if ( node == null ) {
 //        return null;
 //    }
 //    List<DayPeriodRule> list = new List<DayPeriodRule>();
 //    foreach ( LdmlNode child in node.Children ) {
 //        DayPeriodRuleType type;
 //        if ( child.Name == "dayPeriod"
 //            && Enum.TryParse( child.KeyValue, true, out type )) {
 //            list.Add( new DayPeriodRule( type, child.Value )  );
 //        }
 //    }
 //    return list.ToArray();
 //}
 public string[] GetDayPeriods(LocaleFieldSize width,
                               LocaleFieldType compose = LocaleFieldType.Default)
 {
     return(new[] {
         GetDayPeriod("am", width, compose),
         GetDayPeriod("pm", width, compose)
     });
 }
Пример #4
0
        public LocaleFieldPair(LocaleFieldSize format, LocaleFieldType compose = LocaleFieldType.Default)
        {
            var val = (int)format;

            if (compose == LocaleFieldType.StandAlone)
            {
                val |= 4;
            }
            _value = (byte)val;
        }
Пример #5
0
        public string[] GetQuarters(LocaleFieldSize width, LocaleFieldType compose = LocaleFieldType.Default)
        {
            var root = this.Select(new NodePathEntry("months"),
                                   new NodePathEntry("monthContext", new LdmlAttributeValue(LdmlAttribute.Type, compose.ToCode())),
                                   new NodePathEntry("monthWidth", new LdmlAttributeValue(LdmlAttribute.Type, width.ToCode()))
                                   );

            if (root == null)
            {
                return(null);
            }
            return(root.GetList("month", GetMonthIndex));
        }
Пример #6
0
        public static string ToCode(this LocaleFieldSize width)
        {
            switch (width)
            {
            case LocaleFieldSize.Narrow:
                return("narrow");

            case LocaleFieldSize.Short:
                return("short");

            case LocaleFieldSize.Abbreviated:
                return("abbreviated");

            case LocaleFieldSize.Wide:
                return("wide");
            }
            return(null);
        }
Пример #7
0
        public string[] GetDays(LocaleFieldSize width, LocaleFieldType compose = LocaleFieldType.Default)
        {
            var path = new[] {
                new NodePathEntry("days"),
                new NodePathEntry("dayContext", compose.ToCode())
            };
            var      ctx   = this.Select(path);
            LdmlNode found = null;

            if (ctx != null)
            {
                foreach (int i in XUtil.GetClosest((int)width, (int)LocaleFieldSize.Wide))
                {
                    found = ctx.Select("dayWidth", ((LocaleFieldSize)i).ToCode(), LdmlAttribute.Type);
                    if (found != null)
                    {
                        break;
                    }
                }
            }
            if (found == null && compose == LocaleFieldType.StandAlone)
            {
                path[1].Attributes[0].Value = LocaleFieldType.Default.ToCode();
                ctx = this.Select(path);
                if (ctx != null)
                {
                    foreach (int i in XUtil.GetClosest((int)width, (int)LocaleFieldSize.Wide))
                    {
                        found = ctx.Select("dayWidth", ((LocaleFieldSize)i).ToCode(), LdmlAttribute.Type);
                        if (found != null)
                        {
                            break;
                        }
                    }
                }
            }
            if (found == null)
            {
                return(null);
            }

            return(found.GetList("day", GetDayIndex));
        }