~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to beagled/Lucene.Net/Document/DateField.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2004 The Apache Software Foundation
3
 
 * 
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
7
8
 * 
8
9
 * http://www.apache.org/licenses/LICENSE-2.0
9
10
 * 
15
16
 */
16
17
 
17
18
using System;
18
 
using PrefixQuery = Lucene.Net.Search.PrefixQuery;  // for javadoc
19
 
using RangeQuery = Lucene.Net.Search.RangeQuery;    // for javadoc
 
19
using PrefixQuery = Lucene.Net.Search.PrefixQuery;
 
20
using RangeQuery = Lucene.Net.Search.RangeQuery;
20
21
 
21
22
namespace Lucene.Net.Documents
22
23
{
23
 
        
24
 
        /// <summary> Provides support for converting dates to strings and vice-versa.
25
 
        /// The strings are structured so that lexicographic sorting orders by date,
26
 
        /// which makes them suitable for use as field values and search terms.
27
 
        /// 
28
 
        /// <P>Note that this class saves dates with millisecond granularity,
29
 
        /// which is bad for {@link RangeQuery} and {@link PrefixQuery}, as those
30
 
        /// queries are expanded to a BooleanQuery with a potentially large number 
31
 
        /// of terms when searching. Thus you might want to use
32
 
        /// {@link DateTools} instead.
33
 
        /// 
34
 
        /// <P>
35
 
        /// Note: dates before 1970 cannot be used, and therefore cannot be
36
 
        /// indexed when using this class. See {@link DateTools} for an
37
 
        /// alternative without such a limitation.
38
 
        /// 
39
 
        /// </summary>
40
 
        /// <deprecated> If you build a new index, use {@link DateTools} instead. For 
41
 
        /// existing indices you can continue using this class, as it will not be 
42
 
        /// removed in the near future despite being deprecated.
43
 
        /// </deprecated>
44
 
        public class DateField
45
 
        {
46
 
                
47
 
                private DateField()
48
 
                {
49
 
                }
50
 
                
51
 
                // make date strings long enough to last a millenium
52
 
                private static int DATE_LEN = SupportClass.Number.ToString(
 
24
    // for javadoc
 
25
 
 
26
    /// <summary> Provides support for converting dates to strings and vice-versa.
 
27
    /// The strings are structured so that lexicographic sorting orders by date,
 
28
    /// which makes them suitable for use as field values and search terms.
 
29
    /// 
 
30
    /// <P>Note that this class saves dates with millisecond granularity,
 
31
    /// which is bad for {@link RangeQuery} and {@link PrefixQuery}, as those
 
32
    /// queries are expanded to a BooleanQuery with a potentially large number
 
33
    /// of terms when searching. Thus you might want to use
 
34
    /// {@link DateTools} instead.
 
35
    /// 
 
36
    /// <P>
 
37
    /// Note: dates before 1970 cannot be used, and therefore cannot be
 
38
    /// indexed when using this class. See {@link DateTools} for an
 
39
    /// alternative without such a limitation.
 
40
    /// 
 
41
    /// </summary>
 
42
    /// <deprecated> If you build a new index, use {@link DateTools} instead. This class is included for use with existing
 
43
    /// indices and will be removed in a future release.
 
44
    /// </deprecated>
 
45
    public class DateField
 
46
    {
 
47
                
 
48
        private DateField()
 
49
        {
 
50
        }
 
51
                
 
52
        // make date strings long enough to last a millenium
 
53
        private static int DATE_LEN = SupportClass.Number.ToString(
53
54
            1000L * 365 * 24 * 60 * 60 * 1000, 16).Length;
54
55
                
55
 
                public static System.String MIN_DATE_STRING()
56
 
                {
57
 
                        return TimeToString(0);
58
 
                }
59
 
                
60
 
                public static System.String MAX_DATE_STRING()
61
 
                {
62
 
                        char[] buffer = new char[DATE_LEN];
63
 
                        char c = SupportClass.Character.ForDigit(36 - 1, SupportClass.Character.MAX_RADIX);
64
 
                        for (int i = 0; i < DATE_LEN; i++)
65
 
                                buffer[i] = c;
66
 
                        return new System.String(buffer);
67
 
                }
68
 
                
69
 
                /// <summary> Converts a Date to a string suitable for indexing.</summary>
70
 
                /// <throws>  RuntimeException if the date specified in the </throws>
71
 
                /// <summary> method argument is before 1970
72
 
                /// </summary>
73
 
                public static System.String DateToString(System.DateTime date)
74
 
                {
 
56
        public static System.String MIN_DATE_STRING()
 
57
        {
 
58
            return TimeToString(0);
 
59
        }
 
60
                
 
61
        public static System.String MAX_DATE_STRING()
 
62
        {
 
63
            char[] buffer = new char[DATE_LEN];
 
64
            char c = SupportClass.Character.ForDigit(36 - 1, SupportClass.Character.MAX_RADIX);
 
65
            for (int i = 0; i < DATE_LEN; i++)
 
66
                buffer[i] = c;
 
67
            return new System.String(buffer);
 
68
        }
 
69
                
 
70
        /// <summary> Converts a Date to a string suitable for indexing.</summary>
 
71
        /// <throws>  SystemException if the date specified in the </throws>
 
72
        /// <summary> method argument is before 1970
 
73
        /// </summary>
 
74
        public static System.String DateToString(System.DateTime date)
 
75
        {
75
76
            TimeSpan ts = date.Subtract(new DateTime(1970, 1, 1));
76
77
            ts = ts.Subtract(TimeZone.CurrentTimeZone.GetUtcOffset(date));
77
78
            return TimeToString(ts.Ticks / TimeSpan.TicksPerMillisecond);
78
79
        }
79
80
 
80
 
                /// <summary> Converts a millisecond time to a string suitable for indexing.</summary>
81
 
                /// <throws>  RuntimeException if the time specified in the </throws>
82
 
                /// <summary> method argument is negative, that is, before 1970
83
 
                /// </summary>
84
 
                public static System.String TimeToString(long time)
85
 
                {
86
 
                        if (time < 0)
87
 
                                throw new System.SystemException("time '" + time + "' is too early, must be >= 0");
88
 
                        
89
 
                        System.String s = SupportClass.Number.ToString(time, SupportClass.Number.MAX_RADIX);
90
 
                        
91
 
                        if (s.Length > DATE_LEN)
92
 
                                throw new System.SystemException("time '" + time + "' is too late, length of string " + "representation must be <= " + DATE_LEN);
93
 
                        
94
 
                        // Pad with leading zeros
95
 
                        if (s.Length < DATE_LEN)
96
 
                        {
97
 
                                System.Text.StringBuilder sb = new System.Text.StringBuilder(s);
98
 
                                while (sb.Length < DATE_LEN)
99
 
                                        sb.Insert(0, 0);
100
 
                                s = sb.ToString();
101
 
                        }
102
 
                        
103
 
                        return s;
104
 
                }
105
 
                
106
 
                /// <summary>Converts a string-encoded date into a millisecond time. </summary>
107
 
                public static long StringToTime(System.String s)
108
 
                {
109
 
                        return SupportClass.Number.Parse(s, SupportClass.Number.MAX_RADIX);
110
 
                }
111
 
 
112
 
                /// <summary>Converts a string-encoded date into a Date object. </summary>
113
 
                public static System.DateTime StringToDate(System.String s)
114
 
                {
115
 
                        long ticks = StringToTime(s) * TimeSpan.TicksPerMillisecond;
116
 
                        System.DateTime date = new System.DateTime(1970, 1, 1);
117
 
                        date = date.AddTicks(ticks);
118
 
                        date = date.Add(TimeZone.CurrentTimeZone.GetUtcOffset(date));
119
 
                        return date;
120
 
                }
121
 
        }
 
81
        /// <summary> Converts a millisecond time to a string suitable for indexing.</summary>
 
82
        /// <throws>  SystemException if the time specified in the </throws>
 
83
        /// <summary> method argument is negative, that is, before 1970
 
84
        /// </summary>
 
85
        public static System.String TimeToString(long time)
 
86
        {
 
87
            if (time < 0)
 
88
                throw new System.SystemException("time '" + time + "' is too early, must be >= 0");
 
89
                        
 
90
            System.String s = SupportClass.Number.ToString(time, SupportClass.Number.MAX_RADIX);
 
91
                        
 
92
            if (s.Length > DATE_LEN)
 
93
                throw new System.SystemException("time '" + time + "' is too late, length of string " + "representation must be <= " + DATE_LEN);
 
94
                        
 
95
            // Pad with leading zeros
 
96
            if (s.Length < DATE_LEN)
 
97
            {
 
98
                System.Text.StringBuilder sb = new System.Text.StringBuilder(s);
 
99
                while (sb.Length < DATE_LEN)
 
100
                    sb.Insert(0, 0);
 
101
                s = sb.ToString();
 
102
            }
 
103
                        
 
104
            return s;
 
105
        }
 
106
                
 
107
        /// <summary>Converts a string-encoded date into a millisecond time. </summary>
 
108
        public static long StringToTime(System.String s)
 
109
        {
 
110
            return SupportClass.Number.Parse(s, SupportClass.Number.MAX_RADIX);
 
111
        }
 
112
                
 
113
        /// <summary>Converts a string-encoded date into a Date object. </summary>
 
114
        public static System.DateTime StringToDate(System.String s)
 
115
        {
 
116
            long ticks = StringToTime(s) * TimeSpan.TicksPerMillisecond;
 
117
            System.DateTime date = new System.DateTime(1970, 1, 1);
 
118
            date = date.AddTicks(ticks);
 
119
            date = date.Add(TimeZone.CurrentTimeZone.GetUtcOffset(date));
 
120
            return date;
 
121
        }
 
122
    }
122
123
}
 
 
b'\\ No newline at end of file'