public void UnixTimestampShouldShouldBeCastIntoAPlainUtcDate(long secondsSinceEpoch, string expected)
        {
            DateTimeOffset expectedDate = DateTimeOffset.Parse(expected);

            DateTimeOffset date = Epoch.ToDateTimeOffset(secondsSinceEpoch, 0);

            Assert.Equal(secondsSinceEpoch, date.ToSecondsSinceEpoch());
            Assert.Equal(expectedDate, date);
            Assert.Equal(TimeSpan.Zero, date.Offset);
        }
Exemple #2
0
        internal SignatureSafeHandle BuildHandle()
        {
            SignatureSafeHandle signature;

            int result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(),
                                                         (int)when.Offset.TotalMinutes);

            Ensure.Success(result);
            return(signature);
        }
        public void UnixTimestampAndTimezoneOffsetShouldBeCastIntoAUtcDateBearingAnOffset(long secondsSinceEpoch, Int32 offset, string expected)
        {
            DateTimeOffset expectedDate = DateTimeOffset.Parse(expected);

            DateTimeOffset date = Epoch.ToDateTimeOffset(secondsSinceEpoch, offset);

            Assert.Equal(offset, date.Offset.TotalMinutes);
            Assert.Equal(secondsSinceEpoch, date.ToSecondsSinceEpoch());

            Assert.Equal(expectedDate, date);
            Assert.Equal(expectedDate.Offset, date.Offset);
        }
Exemple #4
0
        protected static DateTimeOffset TruncateSubSeconds(DateTimeOffset dto)
        {
            int seconds = dto.ToSecondsSinceEpoch();

            return(Epoch.ToDateTimeOffset(seconds, (int)dto.Offset.TotalMinutes));
        }
Exemple #5
0
 protected static DateTimeOffset TruncateSubSeconds(DateTimeOffset dto)
 {
     int seconds = dto.ToSecondsSinceEpoch();
     return Epoch.ToDateTimeOffset(seconds, (int) dto.Offset.TotalMinutes);
 }
Exemple #6
0
            public UsTarHeader(
                string fileName,
                string namePrefix,
                DateTimeOffset lastModificationTime,
                long size,
                int mode,
                string userId,
                string groupId,
                char typeflag,
                string link,
                string userName,
                string groupName,
                string deviceMajorNumber,
                string deviceMinorNumber)
            {
                #region Length validations

                if (userName.Length > 32)
                {
                    throw new ArgumentException("ustar userName cannot be longer than 32 characters.", "userName");
                }
                if (groupName.Length > 32)
                {
                    throw new ArgumentException("ustar groupName cannot be longer than 32 characters.", "groupName");
                }
                if (userId.Length > 7)
                {
                    throw new ArgumentException("ustar userId cannot be longer than 7 characters.", "userId");
                }
                if (groupId.Length > 7)
                {
                    throw new ArgumentException("ustar groupId cannot be longer than 7 characters.", "groupId");
                }
                if (deviceMajorNumber.Length > 7)
                {
                    throw new ArgumentException("ustar deviceMajorNumber cannot be longer than 7 characters.", "deviceMajorNumber");
                }
                if (deviceMinorNumber.Length > 7)
                {
                    throw new ArgumentException("ustar deviceMinorNumber cannot be longer than 7 characters.", "deviceMinorNumber");
                }
                if (link.Length > 100)
                {
                    throw new ArgumentException("ustar link cannot be longer than 100 characters.", "link");
                }

                #endregion

                this.mode = Convert.ToString(mode, 8).PadLeft(7, '0');
                this.size = size;
                unixTime = Convert.ToString(lastModificationTime.ToSecondsSinceEpoch(), 8).PadLeft(11, '0');
                this.userId = userId.PadLeft(7, '0');
                this.groupId = userId.PadLeft(7, '0');
                this.userName = userName;
                this.groupName = groupName;
                this.typeflag = typeflag;
                this.link = link;
                this.deviceMajorNumber = deviceMajorNumber.PadLeft(7, '0');
                this.deviceMinorNumber = deviceMinorNumber.PadLeft(7, '0');

                this.fileName = fileName;
                this.namePrefix = namePrefix;
            }
Exemple #7
0
        private static IntPtr CreateSignature(string name, string email, DateTimeOffset when)
        {
            IntPtr signature;
            int    result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(), (int)when.Offset.TotalMinutes);

            Ensure.Success(result);

            return(signature);
        }
            public UsTarHeader(
                string fileName,
                string namePrefix,
                DateTimeOffset lastModificationTime,
                long size,
                int mode,
                string userId,
                string groupId,
                char typeflag,
                string link,
                string userName,
                string groupName,
                string deviceMajorNumber,
                string deviceMinorNumber)
            {
                #region Length validations

                if (userName.Length > 32)
                {
                    throw new ArgumentException("ustar userName cannot be longer than 32 characters.", "userName");
                }
                if (groupName.Length > 32)
                {
                    throw new ArgumentException("ustar groupName cannot be longer than 32 characters.", "groupName");
                }
                if (userId.Length > 7)
                {
                    throw new ArgumentException("ustar userId cannot be longer than 7 characters.", "userId");
                }
                if (groupId.Length > 7)
                {
                    throw new ArgumentException("ustar groupId cannot be longer than 7 characters.", "groupId");
                }
                if (deviceMajorNumber.Length > 7)
                {
                    throw new ArgumentException("ustar deviceMajorNumber cannot be longer than 7 characters.", "deviceMajorNumber");
                }
                if (deviceMinorNumber.Length > 7)
                {
                    throw new ArgumentException("ustar deviceMinorNumber cannot be longer than 7 characters.", "deviceMinorNumber");
                }
                if (link.Length > 100)
                {
                    throw new ArgumentException("ustar link cannot be longer than 100 characters.", "link");
                }

                #endregion

                this.mode              = Convert.ToString(mode, 8).PadLeft(7, '0');
                this.size              = size;
                unixTime               = Convert.ToString(lastModificationTime.ToSecondsSinceEpoch(), 8).PadLeft(11, '0');
                this.userId            = userId.PadLeft(7, '0');
                this.groupId           = userId.PadLeft(7, '0');
                this.userName          = userName;
                this.groupName         = groupName;
                this.typeflag          = typeflag;
                this.link              = link;
                this.deviceMajorNumber = deviceMajorNumber.PadLeft(7, '0');
                this.deviceMinorNumber = deviceMinorNumber.PadLeft(7, '0');

                this.fileName   = fileName;
                this.namePrefix = namePrefix;
            }
Exemple #9
0
        private static IntPtr CreateSignature(string name, string email, DateTimeOffset when)
        {
            IntPtr signature;
            int result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(), (int)when.Offset.TotalMinutes);
            Ensure.Success(result);

            return signature;
        }
Exemple #10
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "Signature" /> class.
 /// </summary>
 /// <param name = "name">The name.</param>
 /// <param name = "email">The email.</param>
 /// <param name = "when">The when.</param>
 public Signature(string name, string email, DateTimeOffset when)
     : this(NativeMethods.git_signature_new(name, email, when.ToSecondsSinceEpoch(), (int) when.Offset.TotalMinutes), false)
 {
 }