public void SetUp()
        {
            var dateTime = new DateTime(2012, 12, 21, 13, 23, 54);

            _dateTimeUtc   = dateTime.ReinterpretAsUtc();
            _dateTimeLocal = dateTime.ReinterpretAsLocal();

            _dateTimeUtcAndLocal = new DateTimeUtcAndLocal(_dateTimeUtc, _dateTimeLocal);
        }
Example #2
0
        public static string ToStringISO8601(
            this DateTimeUtcAndLocal @this,
            UtcAndLocalTemplate template = DefaultUtcAndLocalTemplate,
            ISO8601Template dateTemplate = DefaultISO8601Template,
            ISO8601Format format         = DefaultISO8601Format)
        {
            var utcString   = template != UtcAndLocalTemplate.Local ? @this.Utc.ToStringISO8601(dateTemplate, format) : null;
            var localString = template != UtcAndLocalTemplate.Utc ? @this.Local.ToStringISO8601(dateTemplate, format) : null;

            string twoDatesFormatString;

            switch (format)
            {
            case ISO8601Format.Pretty:
                twoDatesFormatString = "{0} / {1}";
                break;

            case ISO8601Format.Formal:
                twoDatesFormatString = "{0} {1}";
                break;

            case ISO8601Format.FileSystemPathFriendly:
                twoDatesFormatString = "{0}--{1}";
                break;

            default:
                throw new ArgumentException("Illegal ISO8601Format");
            }

            switch (template)
            {
            case UtcAndLocalTemplate.Utc:
                return(utcString);

            case UtcAndLocalTemplate.Local:
                return(localString);

            case UtcAndLocalTemplate.UtcAndLocal:
                return(string.Format(twoDatesFormatString, utcString, localString));

            case UtcAndLocalTemplate.LocalAndUtc:
                return(string.Format(twoDatesFormatString, localString, utcString));

            default:
                throw new ArgumentException("Illegal UtcAndLocalTemplate");
            }
        }