Exemplo n.º 1
0
 private static void AddToCache(int key, Timezone timezone)
 {
     if (timezone == null)
     {
         throw new ArgumentException("timezone cannot be null.");
     }
     lock (_syncRoot)
     {
         _cache[key] = timezone;
     }
 }
Exemplo n.º 2
0
        public static Timezone Parse(string timezone)
        {
            // Format +530 or -530
            var match = Pattern.Match(timezone);

            if (match.Success == false)
            {
                throw new ArgumentException(timezone + " is not a valid Timezone value.");
            }
            var  hour = int.Parse(match.Groups["hour"].Value);
            uint min  = uint.Parse(match.Groups["min"].Value);

            return(Timezone.Create(hour, min));
        }
Exemplo n.º 3
0
 private static void AddToCache(int key, Timezone timezone)
 {
     if (timezone == null)
         throw new ArgumentException("timezone cannot be null.");
     _lock.EnterWriteLock();
     try
     {
         _cache[key] = timezone;
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
Exemplo n.º 4
0
 private static bool TryGetFromCache(int key, out Timezone timezone)
 {
     timezone = null;
     lock (_syncRoot)
     {
         if (_cache.TryGetValue(key, out timezone) == true)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 5
0
 private static void AddToCache(int key, Timezone timezone)
 {
     if (timezone == null)
     {
         throw new ArgumentException("timezone cannot be null.");
     }
     _lock.EnterWriteLock();
     try
     {
         _cache[key] = timezone;
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
Exemplo n.º 6
0
 private static bool TryGetFromCache(int key, out Timezone timezone)
 {
     timezone = null;
     _lock.EnterReadLock();
     try
     {
         if (_cache.TryGetValue(key, out timezone) == true)
             return true;
         else
             return false;
     }
     finally
     {
         _lock.ExitReadLock();
     }
 }
Exemplo n.º 7
0
        public static Timezone Create(int hours, uint mins)
        {
            if (hours > 19)
                throw new Exception("Hours cannot be greater than +/- 19.");
            if (mins != 0 && mins != 30 && mins != 45)
                throw new Exception("Minute values can only be 0, 30 or 45.");

            Timezone zone = null;
            // Offset the -19 to always return a positive number
            int key = (20 + hours) * 60 + (int)mins;
            if (TryGetFromCache(key, out zone) == false)
            {
                zone = new Timezone(hours, mins);
                AddToCache(key, zone);
            }
            return zone;
        }
Exemplo n.º 8
0
 private static bool TryGetFromCache(int key, out Timezone timezone)
 {
     timezone = null;
     _lock.EnterReadLock();
     try
     {
         if (_cache.TryGetValue(key, out timezone) == true)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     finally
     {
         _lock.ExitReadLock();
     }
 }
Exemplo n.º 9
0
 public static bool TryParse(string timezone, out Timezone zone)
 {
     zone = null;
     try
     {
         // Format +530 or -530
         var match = Pattern.Match(timezone);
         if (match.Success == false)
         {
             return(false);
         }
         var hour = int.Parse(match.Groups["hour"].Value);
         var min  = uint.Parse(match.Groups["min"].Value);
         zone = Timezone.Create(hour, min);
         return(true);
     }
     catch
     {
         zone = null;
         return(false);
     }
 }
Exemplo n.º 10
0
        public static Timezone Create(int hours, uint mins)
        {
            if (hours > 19)
            {
                throw new Exception("Hours cannot be greater than +/- 19.");
            }
            if (mins != 0 && mins != 30 && mins != 45)
            {
                throw new Exception("Minute values can only be 0, 30 or 45.");
            }

            Timezone zone = null;
            // Offset the -19 to always return a positive number
            int key = (20 + hours) * 60 + (int)mins;

            if (TryGetFromCache(key, out zone) == false)
            {
                zone = new Timezone(hours, mins);
                AddToCache(key, zone);
            }
            return(zone);
        }
Exemplo n.º 11
0
 public static bool TryParse(string timezone, out Timezone zone)
 {
     zone = null;
     try
     {
         // Format +530 or -530
         var match = Pattern.Match(timezone);
         if (match.Success == false)
             return false;
         var hour = int.Parse(match.Groups["hour"].Value);
         var min = uint.Parse(match.Groups["min"].Value);
         zone = Timezone.Create(hour, min);
         return true;
     }
     catch
     {
         zone = null;
         return false;
     }
 }
Exemplo n.º 12
0
 private static void AddToCache(int key, Timezone timezone)
 {
     if (timezone == null)
         throw new ArgumentException("timezone cannot be null.");
     lock (_syncRoot)
     {
         _cache[key] = timezone;
     }
 }
Exemplo n.º 13
0
 private static bool TryGetFromCache(int key, out Timezone timezone)
 {
     timezone = null;
     lock (_syncRoot)
     {
         if (_cache.TryGetValue(key, out timezone) == true)
             return true;
         else
             return false;
     }
     
 }