GetDayName() public method

Returns the culture-specific full name of the specified day of the week based on the culture associated with the current DateTimeFormatInfo object.
public GetDayName ( DayOfWeek dayofweek ) : string
dayofweek DayOfWeek A System.DayOfWeek value.
return string
Exemplo n.º 1
0
        public static String DateTimeAFechaCortaConDiaMesTexto(DateTime fecha)
        {
            System.Globalization.DateTimeFormatInfo mfi = Thread.CurrentThread.CurrentUICulture.DateTimeFormat;
            string DiaSemana = mfi.GetDayName(fecha.DayOfWeek);
            string Mes       = mfi.GetAbbreviatedMonthName(fecha.Month).Replace(".", "");

            String fechaSt = DiaSemana.Substring(0, 3) + "," + IntANDigitos(fecha.Day, 2) + @"" + Mes + @"'" + fecha.Year.ToString().Substring(2, 2);

            return(fechaSt);
        }
        private void VerificationHelper(DateTimeFormatInfo info, string[] expected)
        {
            DayOfWeek[] values = new DayOfWeek[] {
            DayOfWeek.Sunday,
            DayOfWeek.Monday,
            DayOfWeek.Tuesday,
            DayOfWeek.Wednesday,
            DayOfWeek.Thursday,
            DayOfWeek.Friday,
            DayOfWeek.Saturday
            };

            for (int i = 0; i < values.Length; ++i)
            {
                string actual = info.GetDayName(values[i]);
                Assert.Equal(expected[i], actual);
            }
        }
		private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
		{
			int num = 0;
			result = -1;
			if (str.GetNext())
			{
				for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek += DayOfWeek.Monday)
				{
					string dayName = dtfi.GetDayName(dayOfWeek);
					int length = dayName.Length;
					if ((dtfi.HasSpacesInDayNames ? str.MatchSpecifiedWords(dayName, false, ref length) : str.MatchSpecifiedWord(dayName)) && length > num)
					{
						num = length;
						result = (int)dayOfWeek;
					}
				}
			}
			if (result >= 0)
			{
				str.Index += num - 1;
				return true;
			}
			return false;
		}
Exemplo n.º 4
0
        /*=================================MatchDayName==================================
        **Action: Parse the day of week name from string starting at str.Index.
        **Returns: A value from 0 to 6 indicating Sunday to Saturday.
        **Arguments:    str: a __DTString.  The parsing will start from the
        **              next character after str.Index.
        **Exceptions: FormatException if a day of week name can not be found.
        ==============================================================================*/

        private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) {
            // Turkish (tr-TR) got day names with the same prefix.
            int maxMatchStrLen = 0;
            result = -1;
            if (str.GetNext()) {
                for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                    String searchStr = dtfi.GetDayName(i);
                    int matchStrLen = searchStr.Length;
                    if ( dtfi.HasSpacesInDayNames
                            ? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
                            : str.MatchSpecifiedWord(searchStr)) {
                        if (matchStrLen > maxMatchStrLen) {
                            maxMatchStrLen = matchStrLen;
                            result = (int)i;
                        }
                    }
                }
            }
            if (result >= 0) {
                str.Index += maxMatchStrLen - 1;
                return (true);
            }
            return false;
        }
Exemplo n.º 5
0
 private static String FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
 {
     Contract.Assert(dayOfWeek >= 0 && dayOfWeek <= 6, "dayOfWeek >= 0 && dayOfWeek <= 6");
     if (repeat == 3)
     {            
         return (dtfi.GetAbbreviatedDayName((DayOfWeek)dayOfWeek));
     }
     // Call dtfi.GetDayName() here, instead of accessing DayNames property, because we don't
     // want a clone of DayNames, which will hurt perf.
     return (dtfi.GetDayName((DayOfWeek)dayOfWeek));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the abbreviated or full day name for the specified <see cref="DayOfWeek"/> value using, if not null, the <paramref name="nameProvider"/> or
        /// the <see cref="DateTimeFormatInfo"/> specified by <paramref name="info"/>.
        /// </summary>
        /// <param name="dayofweek">
        /// The <see cref="DayOfWeek"/> value to get the day name for.
        /// </param>
        /// <param name="info">
        /// The <see cref="DateTimeFormatInfo"/> to get the name.
        /// </param>
        /// <param name="nameProvider">
        /// The <see cref="ICustomFormatProvider"/> to get the name. This parameter has precedence before the
        /// <paramref name="info"/>. Can be <c>null</c>.
        /// </param>
        /// <param name="abbreviated">
        /// true to get the abbreviated day name; false otherwise.
        /// </param>
        /// <returns>
        /// The full or abbreviated day name specified by <paramref name="dayofweek"/> value.
        /// </returns>
        private static string GetDayName(DayOfWeek dayofweek, DateTimeFormatInfo info, ICustomFormatProvider nameProvider, bool abbreviated)
        {
            if (nameProvider != null)
            {
                return abbreviated ? nameProvider.GetAbbreviatedDayName(dayofweek) : nameProvider.GetDayName(dayofweek);
            }

            return abbreviated ? info.GetAbbreviatedDayName(dayofweek) : info.GetDayName(dayofweek);
        }
		public static string ToString (DateTime dt, TimeSpan? utc_offset, string format, DateTimeFormatInfo dfi)
		{
			// the length of the format is usually a good guess of the number
			// of chars in the result. Might save us a few bytes sometimes
			// Add + 10 for cases like mmmm dddd
			StringBuilder result = new StringBuilder (format.Length + 10);

			// For some cases, the output should not use culture dependent calendar
			DateTimeFormatInfo inv = DateTimeFormatInfo.InvariantInfo;
			if (format == inv.RFC1123Pattern)
				dfi = inv;
			else if (format == inv.UniversalSortableDateTimePattern)
				dfi = inv;

			int i = 0;

			while (i < format.Length) {
				int tokLen;
				bool omitZeros = false;
				char ch = format [i];

				switch (ch) {

				//
				// Time Formats
				//
				case 'h':
					// hour, [1, 12]
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);

					int hr = dt.Hour % 12;
					if (hr == 0)
						hr = 12;

					DateTimeUtils.ZeroPad (result, hr, tokLen == 1 ? 1 : 2);
					break;
				case 'H':
					// hour, [0, 23]
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					DateTimeUtils.ZeroPad (result, dt.Hour, tokLen == 1 ? 1 : 2);
					break;
				case 'm':
					// minute, [0, 59]
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					DateTimeUtils.ZeroPad (result, dt.Minute, tokLen == 1 ? 1 : 2);
					break;
				case 's':
					// second [0, 29]
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					DateTimeUtils.ZeroPad (result, dt.Second, tokLen == 1 ? 1 : 2);
					break;
				case 'F':
					omitZeros = true;
					goto case 'f';
				case 'f':
					// fraction of second, to same number of
					// digits as there are f's

					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					if (tokLen > 7)
						throw new FormatException ("Invalid Format String");

					int dec = (int)((long)(dt.Ticks % TimeSpan.TicksPerSecond) / (long) Math.Pow (10, 7 - tokLen));
					int startLen = result.Length;
					DateTimeUtils.ZeroPad (result, dec, tokLen);

					if (omitZeros) {
						while (result.Length > startLen && result [result.Length - 1] == '0')
							result.Length--;
						// when the value was 0, then trim even preceding '.' (!) It is fixed character.
						if (dec == 0 && startLen > 0 && result [startLen - 1] == '.')
							result.Length--;
					}

					break;
				case 't':
					// AM/PM. t == first char, tt+ == full
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					string desig = dt.Hour < 12 ? dfi.AMDesignator : dfi.PMDesignator;

					if (tokLen == 1) {
						if (desig.Length >= 1)
							result.Append (desig [0]);
					}
					else
						result.Append (desig);

					break;
				case 'z':
					// timezone. t = +/-h; tt = +/-hh; ttt+=+/-hh:mm
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					TimeSpan offset = 
						utc_offset ?? 
						TimeZone.CurrentTimeZone.GetUtcOffset (dt);

					if (offset.Ticks >= 0)
						result.Append ('+');
					else
						result.Append ('-');

					switch (tokLen) {
					case 1:
						result.Append (Math.Abs (offset.Hours));
						break;
					case 2:
						result.Append (Math.Abs (offset.Hours).ToString ("00"));
						break;
					default:
						result.Append (Math.Abs (offset.Hours).ToString ("00"));
						result.Append (':');
						result.Append (Math.Abs (offset.Minutes).ToString ("00"));
						break;
					}
					break;
				case 'K': // 'Z' (UTC) or zzz (Local)
					tokLen = 1;

					if (utc_offset != null || dt.Kind == DateTimeKind.Local) {
						offset = utc_offset ?? TimeZone.CurrentTimeZone.GetUtcOffset (dt);
						if (offset.Ticks >= 0)
							result.Append ('+');
						else
							result.Append ('-');
						result.Append (Math.Abs (offset.Hours).ToString ("00"));
						result.Append (':');
						result.Append (Math.Abs (offset.Minutes).ToString ("00"));
					} else if (dt.Kind == DateTimeKind.Utc)
						result.Append ('Z');
					break;
				//
				// Date tokens
				//
				case 'd':
					// day. d(d?) = day of month (leading 0 if two d's)
					// ddd = three leter day of week
					// dddd+ full day-of-week
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);

					if (tokLen <= 2)
						DateTimeUtils.ZeroPad (result, dfi.Calendar.GetDayOfMonth (dt), tokLen == 1 ? 1 : 2);
					else if (tokLen == 3)
						result.Append (dfi.GetAbbreviatedDayName (dfi.Calendar.GetDayOfWeek (dt)));
					else
						result.Append (dfi.GetDayName (dfi.Calendar.GetDayOfWeek (dt)));

					break;
				case 'M':
					// Month.m(m?) = month # (with leading 0 if two mm)
					// mmm = 3 letter name
					// mmmm+ = full name
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					int month = dfi.Calendar.GetMonth(dt);
					if (tokLen <= 2)
						DateTimeUtils.ZeroPad (result, month, tokLen);
					else if (tokLen == 3)
						result.Append (dfi.GetAbbreviatedMonthName (month));
					else
						result.Append (dfi.GetMonthName (month));

					break;
				case 'y':
					// Year. y(y?) = two digit year, with leading 0 if yy
					// yyy+ full year with leading zeros if needed.
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);

					if (tokLen <= 2)
						DateTimeUtils.ZeroPad (result, dfi.Calendar.GetYear (dt) % 100, tokLen);
					else
						DateTimeUtils.ZeroPad (result, dfi.Calendar.GetYear (dt), tokLen);
					break;

				case 'g':
					// Era name
					tokLen = DateTimeUtils.CountRepeat (format, i, ch);
					result.Append (dfi.GetEraName (dfi.Calendar.GetEra (dt)));
					break;

				//
				// Other
				//
				case ':':
					result.Append (dfi.TimeSeparator);
					tokLen = 1;
					break;
				case '/':
					result.Append (dfi.DateSeparator);
					tokLen = 1;
					break;
				case '\'': case '"':
					tokLen = DateTimeUtils.ParseQuotedString (format, i, result);
					break;
				case '%':
					if (i >= format.Length - 1)
						throw new FormatException ("% at end of date time string");
					if (format [i + 1] == '%')
						throw new FormatException ("%% in date string");

					// Look for the next char
					tokLen = 1;
					break;
				case '\\':
					// C-Style escape
					if (i >= format.Length - 1)
						throw new FormatException ("\\ at end of date time string");

					result.Append (format [i + 1]);
					tokLen = 2;

					break;
				default:
					// catch all
					result.Append (ch);
					tokLen = 1;
					break;
				}
				i += tokLen;
			}
			return result.ToString ();
		}
 private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
 {
     if (repeat == 3)
     {
         return dtfi.GetAbbreviatedDayName((DayOfWeek) dayOfWeek);
     }
     return dtfi.GetDayName((DayOfWeek) dayOfWeek);
 }
Exemplo n.º 9
0
        //
        // Check the word at the current index to see if it matches a day of week name.
        // Return -1 if a match is not found.  Otherwise, a value from 0 to 6 is returned.
        //
        private static int GetDayOfWeekNumber(__DTString str, DateTimeFormatInfo dtfi) {
            //
            // Check the month name specified in dtfi.
            //

            DayOfWeek i;
            
            int maxLen = 0;
            int result = -1;
            //
            // We have to match the day name with the longest length, 
            // since there are cultures which have more than one day of week names
            // with the same prefix.
            //
            int endIndex = str.FindEndOfCurrentWord();
            String dayName=null;
            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                dayName = dtfi.GetDayName(i);
                if (str.MatchSpecifiedWord(dayName, endIndex)) {
                    if (dayName.Length > maxLen) {
                        result = (int)i;
                        maxLen = dayName.Length;
                    }
                }
                }

            if (result > -1) {
                str.Index = endIndex;
                return (result);
            }

            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, dtfi.GetAbbreviatedDayName(i), false))
                {
                    return ((int)i);
                }
            }

            //
            // Check the month name in the invariant culture.
            //
            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, invariantInfo.GetDayName(i), false))
                {
                    return ((int)i);
                }
            }

            for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
            {
                if (MatchWord(str, invariantInfo.GetAbbreviatedDayName(i), false))
                {
                    return ((int)i);
                }
            }

            return (-1);
        }
Exemplo n.º 10
0
        /*=================================MatchDayName==================================
        **Action: Parse the day of week name from string starting at str.Index.
        **Returns: A value from 0 to 6 indicating Sunday to Saturday.
        **Arguments:    str: a __DTString.  The parsing will start from the
        **              next character after str.Index.
        **Exceptions: FormatException if a day of week name can not be found.
        ==============================================================================*/

        private static bool MatchDayName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
            // Turkish (tr-TR) got day names with the same prefix.
            int maxMatchStrLen = 0;
            result = -1;
            if (str.GetNext()) {
                for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
                    String searchStr = dtfi.GetDayName(i);
                    if (str.MatchSpecifiedWord(searchStr)) {
                        int matchStrLen = (searchStr.Length - 1);
                        if (matchStrLen > maxMatchStrLen) {
                            maxMatchStrLen = matchStrLen;
                            result = (int)i;
                        }
                    }                    
                }
            }
            if (result >= 0) {
                str.Index += maxMatchStrLen;
                return (true);
            }            
            return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
        }