예제 #1
0
 public static RubyTime /*!*/ InitializeCopy(RubyTime /*!*/ self, [NotNull] RubyTime /*!*/ other)
 {
     self.SetDateTime(other.DateTime);
     return(self);
 }
예제 #2
0
 public static int DayOfYear(RubyTime self)
 {
     return(self.DateTime.DayOfYear);
 }
예제 #3
0
        public static MutableString /*!*/ FormatTime(RubyContext /*!*/ context, RubyTime /*!*/ self,
                                                     [DefaultProtocol, NotNull] MutableString /*!*/ format)
        {
            MutableString result   = MutableString.CreateMutable(format.Encoding);
            bool          inFormat = false;

            var charEnum = format.GetCharacters();

            while (charEnum.MoveNext())
            {
                var character = charEnum.Current;
                int c         = character.IsValid ? character.Value : -1;

                if (!inFormat)
                {
                    if (c == '%')
                    {
                        inFormat = true;
                    }
                    else
                    {
                        result.Append(character);
                    }
                    continue;
                }
                inFormat = false;
                string dateTimeFormat = null;
                switch (c)
                {
                case '%':
                    result.Append('%');
                    break;

                case 'a':
                    dateTimeFormat = "ddd";
                    break;

                case 'A':
                    dateTimeFormat = "dddd";
                    break;

                case 'b':
                    dateTimeFormat = "MMM";
                    break;

                case 'B':
                    dateTimeFormat = "MMMM";
                    break;

                case 'c':
                    dateTimeFormat = "g";
                    break;

                case 'd':
                    dateTimeFormat = "dd";
                    break;

                case 'D':
                    dateTimeFormat = "MM/dd/yy";
                    break;

                case 'e': {     // Day of the month, blank-padded ( 1..31)
                    int day = self.DateTime.Day;
                    if (day < 10)
                    {
                        result.Append(' ');
                    }
                    result.Append(day.ToString(CultureInfo.InvariantCulture));
                    break;
                }

                case 'H':
                    dateTimeFormat = "HH";
                    break;

                case 'I':
                    dateTimeFormat = "hh";
                    break;

                case 'j':
                    result.AppendFormat("{0:000}", self.DateTime.DayOfYear);
                    break;

                case 'l': {
                    int hour = self.DateTime.Hour;
                    if (hour == 0)
                    {
                        hour = 12;
                    }
                    else if (hour > 12)
                    {
                        hour -= 12;
                    }
                    if (hour < 10)
                    {
                        result.Append(' ');
                    }
                    result.Append(hour.ToString(CultureInfo.InvariantCulture));
                    break;
                }

                case 'm':
                    dateTimeFormat = "MM";
                    break;

                case 'M':
                    dateTimeFormat = "mm";
                    break;

                case 'N':
                    dateTimeFormat = "fffffff00";
                    break;

                case 'p':
                    dateTimeFormat = "tt";
                    break;

                case 'S':
                    dateTimeFormat = "ss";
                    break;

                case 'T':
                    dateTimeFormat = "HH:mm:ss";
                    break;

                case 'U':
                    FormatDayOfWeek(result, self.DateTime, 7);
                    break;

                case 'W':
                    FormatDayOfWeek(result, self.DateTime, 8);
                    break;

                case 'w':
                    result.Append(((int)self.DateTime.DayOfWeek).ToString(CultureInfo.InvariantCulture));
                    break;

                case 'x':
                    dateTimeFormat = "d";
                    break;

                case 'X':
                    dateTimeFormat = "t";
                    break;

                case 'y':
                    dateTimeFormat = "yy";
                    break;

                case 'Y':
                    dateTimeFormat = "yyyy";
                    break;

                case 'Z':
                    dateTimeFormat = "%K";
                    break;

                case 'z':
                    if (context.RubyOptions.Compatibility > RubyCompatibility.Ruby186)
                    {
                        result.Append(self.FormatUtcOffset());
                    }
                    else
                    {
                        result.Append(RubyTime.GetCurrentZoneName());
                    }
                    break;

                default:
                    result.Append('%');
                    result.Append(character);
                    break;
                }

                if (dateTimeFormat != null)
                {
                    result.Append(self.ToString(dateTimeFormat, CultureInfo.InvariantCulture));
                }
            }

            if (inFormat)
            {
                if (context.RubyOptions.Compatibility > RubyCompatibility.Ruby186)
                {
                    return(result.Append('%'));
                }
                return(MutableString.CreateEmpty());
            }

            return(result);
        }
예제 #4
0
 public static int Second(RubyTime self)
 {
     return(self.DateTime.Second);
 }
예제 #5
0
 public static int Month(RubyTime self)
 {
     return(self.DateTime.Month);
 }
예제 #6
0
 public static object Offset(RubyTime /*!*/ self)
 {
     return(Protocols.Normalize(self.GetCurrentZoneOffset().Ticks / 10000000));
 }
예제 #7
0
 public static int Hour(RubyTime self)
 {
     return(self.DateTime.Hour);
 }
예제 #8
0
 public static double SubtractTime(RubyTime /*!*/ self, [NotNull] RubyTime /*!*/ other)
 {
     return((self - other).TotalSeconds);
 }
예제 #9
0
 public static double SubtractTime(RubyTime /*!*/ self, DateTime other)
 {
     return((self.DateTime - other).TotalSeconds);
 }
예제 #10
0
 public static RubyTime /*!*/ SuccessiveSecond(RubyTime /*!*/ self)
 {
     return(AddSeconds(self, 1.0));
 }
예제 #11
0
 public static RubyTime /*!*/ AddSeconds(RubyTime /*!*/ self, [NotNull] RubyTime /*!*/ seconds)
 {
     throw RubyExceptions.CreateTypeError("time + time?");
 }
예제 #12
0
 public static RubyTime /*!*/ Create(RubyClass /*!*/ self, int seconds, int microseconds)
 {
     return(new RubyTime(RubyTime.ToLocalTime(RubyTime.Epoch.AddTicks(RubyTime.ToTicks(seconds, microseconds)))));
 }
예제 #13
0
 public static RubyTime /*!*/ Create(RubyClass /*!*/ self, double seconds)
 {
     return(new RubyTime(RubyTime.ToLocalTime(RubyTime.AddSeconds(RubyTime.Epoch, seconds))));
 }
예제 #14
0
 public static RubyTime /*!*/ Create(RubyClass /*!*/ self, [NotNull] RubyTime /*!*/ other)
 {
     return(new RubyTime(other.Ticks, other.Kind));
 }
예제 #15
0
 public static bool IsUts(RubyTime /*!*/ self)
 {
     return(self.DateTime.Kind == DateTimeKind.Utc);
 }
예제 #16
0
 public static int CompareTo(RubyTime /*!*/ self, [NotNull] RubyTime /*!*/ other)
 {
     return(self.CompareTo(other));
 }
예제 #17
0
 public static object IsDst(RubyContext /*!*/ context, RubyTime /*!*/ self)
 {
     return(self.GetCurrentDst(context));
 }
예제 #18
0
 public static object CompareSeconds(RubyTime /*!*/ self, object other)
 {
     return(null);
 }
예제 #19
0
 public static RubyTime /*!*/ GetUTC(RubyTime /*!*/ self)
 {
     return(new RubyTime(self.ToUniversalTime()));
 }
예제 #20
0
 public static bool Eql(RubyTime /*!*/ self, [NotNull] RubyTime /*!*/ other)
 {
     return(self.Equals(other));
 }
예제 #21
0
 public static int Minute(RubyTime self)
 {
     return(self.DateTime.Minute);
 }
예제 #22
0
 public static bool Eql(RubyTime /*!*/ self, object other)
 {
     return(false);
 }
예제 #23
0
 public static int GetMicroSeconds(RubyTime self)
 {
     return(self.Microseconds);
 }
예제 #24
0
 public static int GetHash(RubyTime /*!*/ self)
 {
     return(self.GetHashCode());
 }
예제 #25
0
 public static int Day(RubyTime self)
 {
     return(self.DateTime.Day);
 }
예제 #26
0
 public static RubyTime /*!*/ SwitchToUtc(RubyTime /*!*/ self)
 {
     self.SetDateTime(self.ToUniversalTime());
     return(self);
 }
예제 #27
0
 public static int DayOfWeek(RubyTime /*!*/ self)
 {
     return((int)self.DateTime.DayOfWeek);
 }
예제 #28
0
 public static RubyTime /*!*/ ToLocalTime(RubyTime /*!*/ self)
 {
     self.SetDateTime(self.ToLocalTime());
     return(self);
 }
예제 #29
0
파일: FileOps.cs 프로젝트: ltwlf/IronSP
        public static int UpdateTimes(RubyClass /*!*/ self, [NotNull] RubyTime /*!*/ accessTime, [NotNull] RubyTime /*!*/ modifiedTime,
                                      [NotNull] MutableString /*!*/ path)
        {
            string   strPath = self.Context.DecodePath(path);
            FileInfo info    = new FileInfo(strPath);

            if (!info.Exists)
            {
                throw RubyExceptions.CreateENOENT("No such file or directory - {0}", strPath);
            }
            info.LastAccessTimeUtc = accessTime.ToUniversalTime();
            info.LastWriteTimeUtc  = modifiedTime.ToUniversalTime();
            return(1);
        }
예제 #30
0
 public static RubyTime /*!*/ Reinitialize(RubyTime /*!*/ self)
 {
     self.DateTime = RubyTime.GetCurrentLocalTime();
     return(self);
 }