public ClockViewModel() { //setup the preferences of the user. var dateFormat = ClockConfiguration.GetPreference(ClockConfiguration.Preferences.DateFormat); if (dateFormat == null) { dateFormat = DateFormats.First().Value; ClockConfiguration.SetPreference(ClockConfiguration.Preferences.DateFormat, dateFormat); } SelectedDateFormat = dateFormat; var timeFormat = ClockConfiguration.GetPreference(ClockConfiguration.Preferences.TimeFormat); if (timeFormat == null) { timeFormat = TimeFormats.First().Value; ClockConfiguration.SetPreference(ClockConfiguration.Preferences.TimeFormat, timeFormat); } SelectedTimeFormat = timeFormat; _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 1); _timer.Tick += timer_Tick; _timer.Start(); }
public void setFormattedDate(int year, int month, int day, DateFormats date_format) { string formatted_date = ""; string new_m = month.ToString(); string new_d = day.ToString(); if (month < 10) { new_m = "0" + month.ToString(); } if (day < 10) { new_d = "0" + day.ToString(); } switch (date_format) { case DateFormats.mDy: formatted_date = new_m.ToString() + "-" + new_d.ToString() + "-" + year.ToString(); break; case DateFormats.dMy: formatted_date = new_d.ToString() + "-" + new_m.ToString() + "-" + year.ToString(); break; case DateFormats.yMd: formatted_date = year.ToString() + "-" + new_m.ToString() + "-" + new_d.ToString(); break; } _formattedDate = formatted_date; }
public string GetMfrDate(ref byte[] keyvaultdata, DateFormats format) { var ret = Encoding.ASCII.GetString(keyvaultdata, 0x9E4, 8); if (!Regex.IsMatch(ret, "^[0-9]{2}-[0-9]{2}-[0-9]{2}$")) { throw new X360UtilsException(X360UtilsException.X360UtilsErrors.DataInvalid); } var split = ret.Split('-'); switch (format) { case DateFormats.YYMMDD: return(string.Format("{0}-{1}-{2}", split[1], split[0], split[2])); case DateFormats.DDMMYY: return(string.Format("{0}-{1}-{2}", split[2], split[0], split[1])); case DateFormats.MMYYDD: return(string.Format("{0}-{1}-{2}", split[0], split[1], split[2])); case DateFormats.DDYYMM: return(string.Format("{0}-{1}-{2}", split[2], split[1], split[0])); case DateFormats.MMDDYY: return(string.Format("{0}-{1}-{2}", split[0], split[2], split[1])); case DateFormats.YYDDMM: return(string.Format("{0}-{1}-{2}", split[1], split[2], split[0])); default: throw new ArgumentOutOfRangeException("format"); } }
public void FullDateFormatFromDateTime() { var dt = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); string convertedDate = DateFormats.FullDateString(dt); string expected = "2018-01-01T00:00:00+00:00"; Assert.Equal(expected, convertedDate); }
public static DateTime ConvertStringToDate(string dateAsString, DateFormats format) { DateTime date = DateTime.MinValue; if (format == DateFormats.DD_MM_YYYY) { date = DateTime.ParseExact(dateAsString, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); } return(date); }
public static string ConvertDateToString(DateTime date, DateFormats format) { string dateAsString = ""; if (format == DateFormats.DD_MM_YYYY) { dateAsString = date.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); } return(dateAsString); }
public static string ConvertToFormat(string Date, DateFormats FromFormat, DateFormats ToFormat = DateFormats.YYYY_MM_DD) { string Day = ""; string Month = ""; string Year = ""; string NewDate = ""; switch (FromFormat) { case DateFormats.DD_MM_YYYY: Date = Date.Substring(0, 10); string[] FullDate = Date.Split('/'); Day = FullDate[0].ToString(); Month = FullDate[1].ToString(); Year = FullDate[2].ToString(); break; case DateFormats.MM_DD_YYYY: Date = Date.Substring(0, 10); string[] FullDateCase2 = Date.Split('/'); Day = FullDateCase2[1].ToString(); Month = FullDateCase2[0].ToString(); Year = FullDateCase2[2].ToString(); break; case DateFormats.YYYY_MM_DD: Date = Date.Substring(0, 10); string[] FullDateCase3 = Date.Split('-'); Day = FullDateCase3[2].ToString(); Month = FullDateCase3[1].ToString(); Year = FullDateCase3[0].ToString(); break; } switch (ToFormat) { case DateFormats.YYYY_MM_DD: NewDate = Year + "-" + Month + "-" + Day; break; case DateFormats.MM_DD_YYYY: NewDate = Month + "/" + Day + "/" + Year; break; case DateFormats.DD_MM_YYYY: NewDate = Day + "/" + Month + "/" + Year; break; } return(NewDate); }
static AppSettings() { #if DEBUG debugBuild = true; #endif DateFormats.Add(new DateFormat("year", "yyyy", "Year")); DateFormats.Add(new DateFormat("month", "MM", "Month number")); DateFormats.Add(new DateFormat("short_month", "MMM", "Short month name")); DateFormats.Add(new DateFormat("long_month", "MMMM", "Long month name")); DateFormats.Add(new DateFormat("day", "dd", "Day")); }
public static DateFormats GetDateFormat(DateFormats def) { dc = ApplicationData.Current.LocalSettings; object o = dc.Values[KEY_DATE]; if (o == null || !Enum.IsDefined(typeof(DateFormats), (string)o)) { return(def); } return((DateFormats)Enum.Parse(typeof(DateFormats), (string)o)); }
public void AddHearingDate() { var date = _c.Test.HearingSchedule.ScheduledDate.Date.ToString(DateFormats.LocalDateFormat(_c.WebConfig.SauceLabsConfiguration.RunningOnSauceLabs())); _browsers[_c.CurrentUser].Clear(HearingSchedulePage.HearingDateTextfield); _browsers[_c.CurrentUser].Driver.WaitUntilVisible(HearingSchedulePage.HearingDateTextfield).SendKeys(date); if (_c.Test.HearingSchedule.MultiDays) { var endDate = _c.Test.HearingSchedule.EndHearingDate.Date.ToString(DateFormats.LocalDateFormat(_c.WebConfig.SauceLabsConfiguration.RunningOnSauceLabs())); _browsers[_c.CurrentUser].Clear(HearingSchedulePage.HearingEndDateTextField); _browsers[_c.CurrentUser].Driver.WaitUntilVisible(HearingSchedulePage.HearingEndDateTextField).SendKeys(endDate); } }
public DateTimePicker() { InitializeComponent(); baseContainer.DataContext = this; // カレンダーで値を選択時 CalCalendar.SelectedDatesChanged += (sender, e) => { CalButton.IsChecked = false; SelectedDate = CalCalendar.SelectedDate.Value; }; // フォーカス更新時 IsKeyboardFocusWithinChanged += (sender, e) => { // DateTimePicker内の全てのコントロールからフォーカスが離れたら if ((bool)e.NewValue == false) { var datetimes = DateFormats .Select(format => Parse(CalText.Text, format)) .Where(datetime => datetime.HasValue) .ToArray(); if (datetimes.Any()) { SelectedDate = datetimes.First().Value; } SetText(this); } }; // テキストボックス.キー入力時 Enterキー押下したらフォーカスを移動する。 CalText.PreviewKeyDown += (sender, e) => { if (e.Key != Key.Enter) { return; } var shift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift; // 次のフォーカスへ移動する。 CalText.MoveFocus(new TraversalRequest(shift ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next)); // 次のフォーカスへENTERキーイベントを渡さない。 e.Handled = true; }; // テキストボックス フォーカス取得時に全選択する。 TextBoxSelectAllWhenGotFocusBehavior.SetIsEnabled(CalText, true); }
private void SetDefaultValues() { Currencies defaultCurrency = SettingsHelper.GetCurrency(); CbbCurr.SelectedIndex = (int)defaultCurrency; DateFormats defaultFormat = SettingsHelper.GetDateFormat(DateFormats.ddmmyyyy); CbbDate.SelectedIndex = (int)defaultFormat; TbEurPnd.Text = SettingsHelper.GetExchange(Exchanges.EurPnd); TbEurDol.Text = SettingsHelper.GetExchange(Exchanges.EurDol); TbEurYen.Text = SettingsHelper.GetExchange(Exchanges.EurYen); TbPndDol.Text = SettingsHelper.GetExchange(Exchanges.PndDol); TbPndYen.Text = SettingsHelper.GetExchange(Exchanges.PndYen); TbDolYen.Text = SettingsHelper.GetExchange(Exchanges.DolYen); }
/// <summary><![CDATA[ /// Format a date/time variable for output. /// ]]></summary> /// <param name="value">DateTime variable to format.</param> /// <param name="format">Date format.</param> /// <returns>String with the date formatted as requested.</returns> public static string DateFormat(this string value, DateFormats format) { if (string.IsNullOrEmpty(value) == false) { DateTime date = Convert.ToDateTime(value); if (date != null) { return(DateFormat(date, format)); } else { return(string.Empty); } } else { return(string.Empty); } }
/// <summary> /// Format a date/time variable for output. /// </summary> /// <example> /// <code> /// using Mezzocode.Halide3; /// ... /// string result = h3Temporal.DateFormat( /// theDate, /// h3Temporal.DateFormats.friendly); /// </code> /// </example> /// <param name="date">DateTime variable to format.</param> /// <param name="format">Date format.</param> /// <returns>String with the date formatted as requested.</returns> public static String DateFormat(System.DateTime date, DateFormats format) { string thedate = string.Empty; try { switch (format) { case DateFormats.sortable: thedate = date.ToString("yyyy-MM-dd"); break; case DateFormats.slashes: thedate = date.ToString("M/d/yyyy"); break; case DateFormats.dots: thedate = date.ToString("M.d.yyyy"); break; case DateFormats.full: thedate = date.ToString("dddd; MMMM d, yyyy"); break; case DateFormats.daily: thedate = date.ToString("dddd; MMMM d"); break; case DateFormats.tidy: thedate = date.ToString("MMM d, yyyy"); break; case DateFormats.weekday: thedate = date.ToString("dddd"); break; case DateFormats.weekdayShort: thedate = date.ToString("ddd"); break; case DateFormats.month: thedate = date.ToString("MMMM"); break; case DateFormats.monthShort: thedate = date.ToString("MMM"); break; case DateFormats.corporate: thedate = date.ToString("M/yyyy"); break; case DateFormats.pressRelease: thedate = date.ToString("MMMM d, yyyy"); break; case DateFormats.RSS: thedate = date.ToUniversalTime().ToString("o"); // thedate = date.ToString("yyyy-MM-dd") + "T" + date.ToString("HH:mm:ss") + "Z"; break; case DateFormats.RSS2: thedate = date.ToUniversalTime().ToString("R"); break; case DateFormats.abbreviatedFull: thedate = date.ToString("ddd-MMM-dd-yyyy"); break; case DateFormats.friendly: double days = Convert.ToInt32(DateDiff(DateDiffComparisonType.days, date, System.DateTime.Now)); thedate = "today"; if (DateDiff(DateDiffComparisonType.hours, date, System.DateTime.Now) < 13 && DateDiff(DateDiffComparisonType.hours, date, System.DateTime.Now) >= 0) { if (DateDiff(DateDiffComparisonType.minutes, date, System.DateTime.Now) < 60 && DateDiff(DateDiffComparisonType.minutes, date, System.DateTime.Now) > 0) { thedate = Convert.ToInt32(DateDiff(DateDiffComparisonType.minutes, date, System.DateTime.Now)).ToString() + " minute"; if (Convert.ToInt32(DateDiff(DateDiffComparisonType.minutes, date, System.DateTime.Now)) != 1) { thedate += "s"; } thedate += " ago"; } else { thedate = Convert.ToInt32(DateDiff(DateDiffComparisonType.hours, date, System.DateTime.Now)).ToString() + " hour"; if (Convert.ToInt32(DateDiff(DateDiffComparisonType.hours, date, System.DateTime.Now)) != 1) { thedate += "s"; } thedate += " ago"; } } else { if (days < 7 && days > 0) { if (days == 1) { thedate = "yesterday"; } else { thedate = days.ToString() + " day"; if (days != 1) thedate += "s"; thedate += " ago, on " + date.ToString("M/d/yyyy"); } } else { if (days == 7) { thedate = "a week ago"; } else { thedate = "on " + date.ToString("M/d/yyyy"); } } } break; default: thedate = date.ToString("M-d-yyyy"); break; } } catch { } return (thedate); }
/// <summary> /// Преобразовать значение в SQL строку /// </summary> /// <param name="function">Функция</param> /// <param name="convertValue">делегат для преобразования констант</param> /// <param name="convertIdentifier">делегат для преобразования идентификаторов</param> /// <returns></returns> public override string FunctionToSql( SQLWhereLanguageDef sqlLangDef, Function value, delegateConvertValueToQueryValueString convertValue, delegatePutIdentifierToBrackets convertIdentifier) { ExternalLangDef langDef = sqlLangDef as ExternalLangDef; if (value.FunctionDef.StringedView == "TODAY") { return("sysdate"); } if ( value.FunctionDef.StringedView == "YearPart" || value.FunctionDef.StringedView == "MonthPart" || value.FunctionDef.StringedView == "DayPart") { return(string.Format("EXTRACT ({0} FROM {1})", value.FunctionDef.StringedView.Substring(0, value.FunctionDef.StringedView.Length - 4), langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if ( value.FunctionDef.StringedView == "hhPart") { return(string.Format("TO_CHAR({1}, \'{0}\')", "HH24", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "miPart") { return(string.Format("TO_CHAR({1}, \'{0}\')", "MI", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "DayOfWeek") { // здесь требуется преобразование из DATASERVICE return(string.Format("TO_CHAR({1}, \'{0}\')", "D", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == langDef.funcDayOfWeekZeroBased) { throw new NotImplementedException(string.Format("Function {0} is not implemented for Oracle", langDef.funcDayOfWeekZeroBased)); } if (value.FunctionDef.StringedView == langDef.funcDaysInMonth) { // здесь требуется преобразование из DATASERVICE string.Format("to_char(last_day(to_date('01.'||{0}||'.'||{1},'dd.mm.yyyy')),'dd')", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier)); return(string.Empty); } if (value.FunctionDef.StringedView == "OnlyDate") { return(string.Format("TRUNC({0})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "CurrentUser") { return(string.Format("'{0}'", CurrentUserService.CurrentUser.FriendlyName)); // у нее нет параметров // langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier)); } if (value.FunctionDef.StringedView == "OnlyTime") { return(string.Format("TRUNC({0})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "DATEDIFF") { var ret = string.Empty; if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Year") { ret = string.Format("EXTRACT (YEAR FROM {1}) - EXTRACT (YEAR FROM {0})", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Month") { ret = string.Format("(EXTRACT (YEAR FROM {1}) - EXTRACT (YEAR FROM {0})) * 12 + (EXTRACT (MONTH FROM {1}) - EXTRACT (MONTH FROM {0}))", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Week") { ret = string.Format("(TRUNC({1},'DAY') - TRUNC({0},'DAY'))/7", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Day") { ret = string.Format("TRUNC({1}) - TRUNC({0})", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "quarter") { ret = string.Format("(EXTRACT (YEAR FROM {1}) - EXTRACT (YEAR FROM {0})) * 4 + (TO_CHAR({1}, 'Q') - TO_CHAR({0}, 'Q'))", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } return(ret); } if (value.FunctionDef.StringedView == "SUM" || value.FunctionDef.StringedView == "AVG" || value.FunctionDef.StringedView == "MAX" || value.FunctionDef.StringedView == "MIN") { ICSSoft.STORMNET.Business.LoadingCustomizationStruct lcs = new ICSSoft.STORMNET.Business.LoadingCustomizationStruct(null); DetailVariableDef dvd = (DetailVariableDef)value.Parameters[0]; lcs.LoadingTypes = new Type[] { dvd.View.DefineClassType }; lcs.View = new View(); lcs.View.DefineClassType = dvd.View.DefineClassType; lcs.View.AddProperty(dvd.ConnectMasterPorp); string[] prevRetVars = langDef.retVars; langDef.retVars = new string[] { dvd.ConnectMasterPorp }; ArrayList al = new ArrayList(); object par = langDef.TransformObject(value.Parameters[1], dvd.StringedView, al); foreach (string s in al) { lcs.View.AddProperty(s); } string Slct = GenerateSQLSelect(lcs, false).Replace("STORMGENERATEDQUERY", "SGQ" + Guid.NewGuid().ToString().Replace("-", string.Empty)); string CountIdentifier = convertIdentifier("g" + Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 29)); // FunctionalLanguage.Function numFunc = (value.Parameters[1] as FunctionalLanguage.Function); string sumExpression = langDef.SQLTranslSwitch(par, convertValue, convertIdentifier); string res = string.Empty; res = string.Format( "( SELECT {0} From ( " + "SELECT {6}({5}) {0},{1} from ( {4} )pip group by {1} ) " + " ahh where {1} in ({3}", CountIdentifier, convertIdentifier(dvd.ConnectMasterPorp), convertIdentifier(Information.GetClassStorageName(dvd.View.DefineClassType)), convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[0]), // convertIdentifier(dvd.OwnerConnectProp), Slct, // ВНИМАНИЕ ЗДЕСЬ ТРЕБУЕТСЯ ИЗМЕНИТь ISNULL на вычислитель в определенном DATASERVICE "NVL(" + sumExpression + ",0)", value.FunctionDef.StringedView); for (int k = 0; k < dvd.OwnerConnectProp.Length; k++) { res += "," + convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[k]); } res += "))"; langDef.retVars = prevRetVars; return(res); } if (value.FunctionDef.StringedView == langDef.funcCountWithLimit || value.FunctionDef.StringedView == "Count") { var lcs = new ICSSoft.STORMNET.Business.LoadingCustomizationStruct(null); var dvd = (DetailVariableDef)value.Parameters[0]; lcs.LoadingTypes = new Type[] { dvd.View.DefineClassType }; lcs.View = dvd.View.Clone(); lcs.LimitFunction = value.FunctionDef.StringedView == langDef.funcCountWithLimit ? langDef.TransformVariables((FunctionalLanguage.Function)value.Parameters[1], dvd.StringedView, null) : langDef.GetFunction("True"); var prevRetVars = langDef.retVars; langDef.retVars = new string[] { dvd.ConnectMasterPorp }; var Slct = GenerateSQLSelect(lcs, true); var CountIdentifier = convertIdentifier("g" + Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 29)); var res = string.Format( "( NVL( ( SELECT {0} From ( " + "SELECT Count(*) {0},{1} from ( {4} )pip group by {1} ) " + " ahh where {1} in ({3}", CountIdentifier, convertIdentifier(dvd.ConnectMasterPorp), convertIdentifier(Information.GetClassStorageName(dvd.View.DefineClassType)), convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[0]), Slct); for (int k = 1; k < dvd.OwnerConnectProp.Length; k++) { res += "," + convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[k]); } res += ")),0))"; langDef.retVars = prevRetVars; return(res); } if (value.FunctionDef.StringedView == langDef.funcToChar) { if (value.Parameters.Count == 2) { return(string.Format( "SUBSTR(TO_CHAR({0}), 1, {1})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), value.Parameters[1])); } if (value.Parameters.Count == 3) { return(string.Format( "SUBSTR(TO_CHAR({0}, {2}), 1, {1})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), value.Parameters[1], DateFormats.GetOracleDateFormat((int)value.Parameters[2]))); } } else { throw new NotImplementedException(string.Format( "Функция {0} не реализована для Oracle", value.FunctionDef.StringedView)); } return(string.Empty); }
public string GetDateFormatById(int dateFormatId) { return(DateFormats.FirstOrDefault(x => x.DateFormatId == dateFormatId)?.DateFormat); }
public static void SaveDateFormat(DateFormats dateFormat) { dc = ApplicationData.Current.LocalSettings; dc.Values[KEY_DATE] = dateFormat.ToString(); }
/// <summary> /// 将具体的日期转换成目标格式的日期字符串 /// </summary> /// <param name="dateValue"></param> /// <param name="dateFormat"></param> /// <param name="dateSeperator">日期各个部分之间的分割符号</param> /// <returns></returns> public static string UnParse(DateTime dateValue, DateFormats dateFormat, string dateSeperator) { string resultValue = string.Empty; int resultYear = dateValue.Year; int resultMonth = dateValue.Month; int resultDay = dateValue.Day; switch (dateFormat) { case DateFormats.MDY: resultValue = string.Format("{1}{0}{2}{0}{3}", dateSeperator, resultMonth, resultDay, resultYear); break; case DateFormats.DMY: resultValue = string.Format("{1}{0}{2}{0}{3}", dateSeperator, resultDay, resultMonth, resultYear); break; case DateFormats.YMD: default: resultValue = string.Format("{1}{0}{2}{0}{3}", dateSeperator, resultYear, resultMonth, resultDay); break; } return resultValue; }
public NepaliDate ToBS(DateTime gDate, DateFormats date_format = DateFormats.mDy) { gDate = gDate.Date; //Breaking given english date int yy = 0; int mm = 0; int dd = 0; yy = gDate.Year; mm = gDate.Month; dd = gDate.Day; //English month data int[] month = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] lmonth = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int def_eyy = 0; int def_nyy = 0; int def_nmm = 0; int def_ndd = 0; int total_eDays = 0; int total_nDays = 0; int a = 0; int m = 0; int y = 0; int i = 0; int j = 0; //Initialize english date Tuple <int[], int[], int> initializationDates = conversionStartDateData.getClosestEnglishDateAndNepaliDate(gDate); int[] english_init_date = initializationDates.Item1; int[] nepali_init_date = initializationDates.Item2; // def_eyy = 1944; def_eyy = english_init_date[0]; //Equivalent nepali date def_nyy = nepali_init_date[0]; def_nmm = nepali_init_date[1]; def_ndd = nepali_init_date[2]; //Initializations total_eDays = 0; total_nDays = 0; a = 0; m = 0; i = 0; j = 0; //count total number of english days using standard date functions total_eDays = Convert.ToInt32((gDate - new DateTime(def_eyy, 01, 01)).TotalDays) + 1; //below i is the starting nepali year, used in looping to loop through years above the specified year i = def_nyy; j = def_nmm; total_nDays = def_ndd; m = def_nmm; y = def_nyy; //Count nepali date from array while ((!(total_eDays == 0))) { a = nepaliDateData.getLastDayOfMonthNep(i, j); total_nDays += 1; if ((total_nDays > a)) { m += 1; total_nDays = 1; j += 1; } if ((m > 12)) { y += 1; m = 1; } if ((j > 12)) { j = 1; i += 1; } total_eDays -= 1; } NepaliDate nep_date = new NepaliDate(); nep_date.npDay = total_nDays; nep_date.npDaysInMonth = a; nep_date.npMonth = m; nep_date.npYear = y; //1 is added since we are using Sunday as 1 although it is 0 nep_date.dayNumber = (int)gDate.DayOfWeek + 1; nep_date.dayName = gDate.DayOfWeek.ToString(); nep_date.setFormattedDate(y, m, total_nDays, date_format); return(nep_date); }
/// <summary><![CDATA[ /// Format a date/time variable for output. /// ]]></summary> /// <param name="date">DateTime variable to format.</param> /// <param name="format">Date format.</param> /// <returns>String with the date formatted as requested.</returns> public static string DateFormat(this DateTime date, DateFormats format) { string thedate = string.Empty; try { switch (format) { case DateFormats.Sortable: thedate = date.ToString("yyyy-MM-dd"); break; case DateFormats.Slashes: thedate = date.ToString("M/d/yyyy"); break; case DateFormats.Dots: thedate = date.ToString("M.d.yyyy"); break; case DateFormats.Full: thedate = date.ToString("dddd; MMMM d, yyyy"); break; case DateFormats.Daily: thedate = date.ToString("dddd; MMMM d"); break; case DateFormats.Tidy: thedate = date.ToString("MMM d, yyyy"); break; case DateFormats.Weekday: thedate = date.ToString("dddd"); break; case DateFormats.WeekdayShort: thedate = date.ToString("ddd"); break; case DateFormats.Month: thedate = date.ToString("MMMM"); break; case DateFormats.MonthShort: thedate = date.ToString("MMM"); break; case DateFormats.Corporate: thedate = date.ToString("M/yyyy"); break; case DateFormats.PressRelease: thedate = date.ToString("MMMM d, yyyy"); break; case DateFormats.European: thedate = date.ToString("dd-MMM-yyyy").ToUpper(); break; case DateFormats.Rss: case DateFormats.Utc: thedate = date.ToString("yyyy-MM-dd") + "T" + date.ToString("HH:mm:ss") + "Z"; break; case DateFormats.AbbreviatedFull: thedate = date.ToString("ddd-MMM-dd-yyyy"); break; case DateFormats.Friendly: double days = Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Days))); bool future = false; if (DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes) <= 0) { future = true; } thedate = "today"; if (Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours)) < 13 && Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours)) >= 0) { if (Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes)) < 60 && Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes)) > 0) { thedate = Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes))).ToString() + " minute"; if (Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } else { thedate = Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours))).ToString() + " hour"; if (Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } } else { if (days < 7 && days > 0) { if (days == 1) { thedate = (future ? "tomorrow" : "yesterday"); } else { thedate = days.ToString() + " day"; if (days != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago") + ", on " + date.ToString("M/d/yyyy"); } } else { if (days == 7) { thedate = (future ? "a week from now" : "a week ago"); } else { thedate = "on " + date.ToString("M/d/yyyy"); } } } break; case DateFormats.Abstract: days = Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Days)); future = false; if (DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes) <= 0) { future = true; } thedate = "today"; if (Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours)) < 24 && Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours)) >= 0) { if (Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes)) < 60 && Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes)) > 0) { thedate = Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes))).ToString() + " minute"; if (Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Minutes))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } else { thedate = Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours))).ToString() + " hour"; if (Convert.ToInt32(Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Hours))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } } else { if (days < 7 && days > 0) { if (days <= 1) { thedate = (future ? "tomorrow" : "yesterday"); } else { thedate = FormatAbstract(days, "day", 0.3, 0.6, 0.8, future); } } else { double weeks = days / 7; if (weeks < 4) { thedate = FormatAbstract(weeks, "week", 0.3, 0.6, 0.8, future); } else { double months = Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Months)); if (months < 12) { thedate = FormatAbstract(months, "month", 0.3, 0.6, 0.8, future); } else { double years = Math.Abs(DateDiff <double>(date, System.DateTime.Now, DateDiffComparisonType.Years)); thedate = FormatAbstract(years, "year", 0.3, 0.6, 0.8, future); } } } } break; default: thedate = date.ToString("M-d-yyyy"); break; } } catch { } return(thedate); }
/// <summary> /// 将日期字符串解析成具体的日期 /// </summary> /// <param name="dateString">日期字符串</param> /// <param name="dateFormat">日期格式</param> /// <param name="dateSeperator">日期各个部分之间的分割符号</param> /// <param name="defaultValue">解析失败时返回的默认日期</param> /// <returns>返回解析后的日期,如果解析失败则返回设定的默认日期defaultValue</returns> /// <remarks> /// 对于通常日期的格式解析请使用系统自身的 DateTime.TryParser("",IFormatProvider)。 /// 在某些无法使用以上方法的时候才考虑使用本方法。 /// </remarks> public static DateTime Parse(string dateString, DateFormats dateFormat,DateTime defaultValue, params string[] dateSeperator) { DateTime resultDate = defaultValue; if (string.IsNullOrEmpty(dateString) == false) { if (dateSeperator == null || dateSeperator.Length == 0) { dateSeperator = new string[] { "/", "-", "_", "\\" }; } try { string[] dateStrings = dateString.Split(dateSeperator, StringSplitOptions.RemoveEmptyEntries); if (dateStrings.Length == 3) { int resultYear = 0; int resultMonth = 0; int resultDay = 0; switch (dateFormat) { case DateFormats.MDY: resultYear = Convert.ToInt32(dateStrings[2]); resultMonth = Convert.ToInt32(dateStrings[0]); resultDay = Convert.ToInt32(dateStrings[1]); break; case DateFormats.DMY: resultYear = Convert.ToInt32(dateStrings[2]); resultMonth = Convert.ToInt32(dateStrings[1]); resultDay = Convert.ToInt32(dateStrings[0]); break; case DateFormats.YMD: default: resultYear = Convert.ToInt32(dateStrings[0]); resultMonth = Convert.ToInt32(dateStrings[1]); resultDay = Convert.ToInt32(dateStrings[2]); break; } resultDate = new DateTime(resultYear, resultMonth, resultDay); } } catch { resultDate = defaultValue; } } return resultDate; }
/// <summary> /// Format a date/time variable for output. /// </summary> /// <example> /// <code> /// using Mezzocode.Halide3; /// ... /// string result = h3Temporal.DateFormat( /// theDate, /// h3Temporal.DateFormats.friendly); /// </code> /// </example> /// <param name="date">DateTime variable to format.</param> /// <param name="format">Date format.</param> /// <returns>String with the date formatted as requested.</returns> public static String DateFormat(string date, DateFormats format) { return DateFormat(Convert.ToDateTime(date), format); }
/// <summary> /// Format a date/time variable for output. /// </summary> /// <example> /// <code> /// using Argentini.Halide; /// ... /// string result = H3Temporal.DateFormat( /// theDate, /// H3Temporal.DateFormats.friendly); /// </code> /// </example> /// <param name="date">DateTime variable to format.</param> /// <param name="format">Date format.</param> /// <returns>String with the date formatted as requested.</returns> public static String DateFormat(System.DateTime date, DateFormats format) { string thedate = string.Empty; try { switch (format) { case DateFormats.Sortable: thedate = date.ToString("yyyy-MM-dd"); break; case DateFormats.Slashes: thedate = date.ToString("M/d/yyyy"); break; case DateFormats.Dots: thedate = date.ToString("M.d.yyyy"); break; case DateFormats.Full: thedate = date.ToString("dddd; MMMM d, yyyy"); break; case DateFormats.Daily: thedate = date.ToString("dddd; MMMM d"); break; case DateFormats.Tidy: thedate = date.ToString("MMM d, yyyy"); break; case DateFormats.Weekday: thedate = date.ToString("dddd"); break; case DateFormats.WeekdayShort: thedate = date.ToString("ddd"); break; case DateFormats.Month: thedate = date.ToString("MMMM"); break; case DateFormats.MonthShort: thedate = date.ToString("MMM"); break; case DateFormats.Corporate: thedate = date.ToString("M/yyyy"); break; case DateFormats.PressRelease: thedate = date.ToString("MMMM d, yyyy"); break; case DateFormats.Rss: thedate = date.ToUniversalTime().ToString("o"); // thedate = date.ToString("yyyy-MM-dd") + "T" + date.ToString("HH:mm:ss") + "Z"; break; case DateFormats.Rss2: thedate = date.ToUniversalTime().ToString("R"); break; case DateFormats.AbbreviatedFull: thedate = date.ToString("ddd-MMM-dd-yyyy"); break; case DateFormats.Friendly: double days = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Days, date, System.DateTime.Now))); bool future = false; if (DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now) <= 0) { future = true; } thedate = "today"; if (Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) < 13 && Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) >= 0) { if (Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) < 60 && Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) > 0) { thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))).ToString() + " minute"; if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } else { thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))).ToString() + " hour"; if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } } else { if (days < 7 && days > 0) { if (days == 1) { thedate = (future ? "tomorrow" : "yesterday"); } else { thedate = days.ToString() + " day"; if (days != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago") + ", on " + date.ToString("M/d/yyyy"); } } else { if (days == 7) { thedate = (future ? "a week from now" : "a week ago"); } else { thedate = "on " + date.ToString("M/d/yyyy"); } } } break; case DateFormats.Abstract: days = Math.Abs(DateDiff(DateDiffComparisonType.Days, date, System.DateTime.Now)); future = false; if (DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now) <= 0) { future = true; } thedate = "today"; if (Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) < 24 && Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now)) >= 0) { if (Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) < 60 && Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now)) > 0) { thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))).ToString() + " minute"; if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Minutes, date, System.DateTime.Now))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } else { thedate = Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))).ToString() + " hour"; if (Convert.ToInt32(Math.Abs(DateDiff(DateDiffComparisonType.Hours, date, System.DateTime.Now))) != 1) { thedate += "s"; } thedate += (future ? " from now" : " ago"); } } else { if (days < 7 && days > 0) { if (days <= 1) { thedate = (future ? "tomorrow" : "yesterday"); } else { thedate = FormatAbstract(days, "day", 0.3, 0.6, 0.8, future); } } else { double weeks = days/7; if (weeks < 4) { thedate = FormatAbstract(weeks, "week", 0.3, 0.6, 0.8, future); } else { double months = Math.Abs(DateDiff(DateDiffComparisonType.Months, date, System.DateTime.Now)); if (months < 12) { thedate = FormatAbstract(months, "month", 0.3, 0.6, 0.8, future); } else { double years = Math.Abs(DateDiff(DateDiffComparisonType.Years, date, System.DateTime.Now)); thedate = FormatAbstract(years, "year", 0.3, 0.6, 0.8, future); } } } } break; default: thedate = date.ToString("M-d-yyyy"); break; } } catch {} return (thedate); }
/// <summary> /// Преобразовать значение в SQL строку /// </summary> /// <param name="function">Функция</param> /// <param name="convertValue">делегат для преобразования констант</param> /// <param name="convertIdentifier">делегат для преобразования идентификаторов</param> /// <returns></returns> public override string FunctionToSql( SQLWhereLanguageDef sqlLangDef, Function value, delegateConvertValueToQueryValueString convertValue, delegatePutIdentifierToBrackets convertIdentifier) { ExternalLangDef langDef = sqlLangDef as ExternalLangDef; if (value.FunctionDef.StringedView == "TODAY") { return("current_timestamp"); } if ( value.FunctionDef.StringedView == "YearPart" || value.FunctionDef.StringedView == "MonthPart" || value.FunctionDef.StringedView == "DayPart") { return(string.Format("EXTRACT ({0} FROM {1})", value.FunctionDef.StringedView.Substring(0, value.FunctionDef.StringedView.Length - 4), langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if ( value.FunctionDef.StringedView == "hhPart" || value.FunctionDef.StringedView == "miPart") { string strView = value.FunctionDef.StringedView == "hhPart" ? "HOUR" : "MINUTE"; return(string.Format("EXTRACT ({0} FROM {1})", strView, langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "DayOfWeek") { return(string.Format("EXTRACT ({0} FROM {1})", "ISODOW", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == langDef.funcDayOfWeekZeroBased) { return(string.Format("EXTRACT ({0} FROM {1})", "DOW", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == langDef.funcDaysInMonth) { // здесь требуется преобразование из DATASERVICE return(string.Format("DATE_PART('days', DATE_TRUNC('month', to_date('01.{0}.{1}','dd.mm.yyyy')) + '1 MONTH'::INTERVAL - DATE_TRUNC('month', to_date('01.{0}.{1}','dd.mm.yyyy')) )", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "OnlyDate") { return(string.Format("date_trunc('day',{0})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "CurrentUser") { return(string.Format("'{0}'", CurrentUserService.CurrentUser.FriendlyName)); } if (value.FunctionDef.StringedView == "OnlyTime") { return(string.Format("(to_timestamp(0)+({0} - {0}::date))", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier))); } if (value.FunctionDef.StringedView == "DATEDIFF") { var ret = string.Empty; if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Year") { ret = string.Format("DATE_PART('year', {1}) - DATE_PART('year', {0})", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Month") { ret = string.Format("(DATE_PART('year', {1}) - DATE_PART('year', {0})) * 12 + (DATE_PART('month', {1}) - DATE_PART('month', {0}))", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Week") { ret = string.Format("TRUNC(DATE_PART('day', {1} - {0})/7)", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "Day") { ret = string.Format("DATE_PART('day', {1} - {0})", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } else if (langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier) == "quarter") { ret = string.Format("EXTRACT(QUARTER FROM {1})-EXTRACT(QUARTER FROM {0})+4*(DATE_PART('year', {1}) - DATE_PART('year', {0}))", langDef.SQLTranslSwitch(value.Parameters[1], convertValue, convertIdentifier), langDef.SQLTranslSwitch(value.Parameters[2], convertValue, convertIdentifier)); } return(ret); } if (value.FunctionDef.StringedView == "SUM" || value.FunctionDef.StringedView == "AVG" || value.FunctionDef.StringedView == "MAX" || value.FunctionDef.StringedView == "MIN") { var lcs = new ICSSoft.STORMNET.Business.LoadingCustomizationStruct(null); var dvd = (DetailVariableDef)value.Parameters[0]; lcs.LoadingTypes = new Type[] { dvd.View.DefineClassType }; lcs.View = new View(); lcs.View.DefineClassType = dvd.View.DefineClassType; lcs.View.AddProperty(dvd.ConnectMasterPorp); var prevRetVars = langDef.retVars; langDef.retVars = new string[] { dvd.ConnectMasterPorp }; var al = new ArrayList(); var par = langDef.TransformObject(value.Parameters[1], dvd.StringedView, al); foreach (string s in al) { lcs.View.AddProperty(s); } var Slct = GenerateSQLSelect(lcs, false).Replace("STORMGENERATEDQUERY", "SGQ" + Guid.NewGuid().ToString().Replace("-", string.Empty)); var CountIdentifier = convertIdentifier("g" + Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 29)); string sumExpression = langDef.SQLTranslSwitch(par, convertValue, convertIdentifier); string res = string.Empty; res = string.Format( "( SELECT {0} From ( " + "SELECT {6}({5}) {0},{1} from ( {4} )pip group by {1} ) " + " ahh where {1} in ({3}", CountIdentifier, convertIdentifier(dvd.ConnectMasterPorp), convertIdentifier(Information.GetClassStorageName(dvd.View.DefineClassType)), convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[0]), // convertIdentifier(dvd.OwnerConnectProp), Slct, // ВНИМАНИЕ ЗДЕСЬ ТРЕБУЕТСЯ ИЗМЕНИТь ISNULL на вычислитель в определенном DATASERVICE "COALESCE(" + sumExpression + ",0)", value.FunctionDef.StringedView); for (int k = 0; k < dvd.OwnerConnectProp.Length; k++) { res += "," + convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[k]); } res += "))"; langDef.retVars = prevRetVars; return(res); } if (value.FunctionDef.StringedView == langDef.funcCountWithLimit || value.FunctionDef.StringedView == "Count") { var lcs = new ICSSoft.STORMNET.Business.LoadingCustomizationStruct(null); var dvd = (DetailVariableDef)value.Parameters[0]; lcs.LoadingTypes = new Type[] { dvd.View.DefineClassType }; lcs.View = dvd.View.Clone(); lcs.LimitFunction = value.FunctionDef.StringedView == langDef.funcCountWithLimit ? langDef.TransformVariables((FunctionalLanguage.Function)value.Parameters[1], dvd.StringedView, null) : langDef.GetFunction("True"); var prevRetVars = langDef.retVars; langDef.retVars = new string[] { dvd.ConnectMasterPorp }; var Slct = GenerateSQLSelect(lcs, true); var CountIdentifier = convertIdentifier("g" + Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 29)); var res = string.Format( "( COALESCE( ( SELECT {0} From ( " + "SELECT Count(*) {0},{1} from ( {4} )pip group by {1} ) " + " ahh where {1} in ({3}", CountIdentifier, convertIdentifier(dvd.ConnectMasterPorp), convertIdentifier(Information.GetClassStorageName(dvd.View.DefineClassType)), convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[0]), Slct); for (int k = 1; k < dvd.OwnerConnectProp.Length; k++) { res += "," + convertIdentifier("STORMGENERATEDQUERY") + "." + convertIdentifier(dvd.OwnerConnectProp[k]); } res += ")),0))"; langDef.retVars = prevRetVars; return(res); } if (value.FunctionDef.StringedView == langDef.funcToChar) { if (value.Parameters.Count == 2) { return(string.Format( "({0})::varchar({1})", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), value.Parameters[1])); } if (value.Parameters.Count == 3) { return(string.Format( "(to_char({0}, '{2}')::varchar({1}))", langDef.SQLTranslSwitch(value.Parameters[0], convertValue, convertIdentifier), value.Parameters[1], DateFormats.GetPostgresDateFormat((int)value.Parameters[2]))); } } throw new NotImplementedException(string.Format( "Функция {0} не реализована для Postgres", value.FunctionDef.StringedView)); }
static DateFormat() { DateFormats.Add("yyyy{0}MM{0}dd HH{1}mm{1}ss"); DateFormats.Add("yyyy{0}MM{0}dd hh{1}mm{1}ss"); Current = DateFormats[1]; }
/// <summary> /// 将日期字符串解析成具体的日期 /// </summary> /// <param name="dateString">日期字符串</param> /// <param name="dateFormat">日期格式</param> /// <param name="dateSeperator">日期各个部分之间的分割符号</param> /// <returns>返回解析后的日期,如果解析失败则返回系统的最小日期</returns> /// <remarks> /// 对于通常日期的格式解析请使用系统自身的 DateTime.TryParser("",IFormatProvider)。 /// 在某些无法使用以上方法的时候才考虑使用本方法。 /// </remarks> public static DateTime Parse(string dateString, DateFormats dateFormat, params string[] dateSeperator) { return Parse(dateString, dateFormat, DateTimeHelper.Min, dateSeperator); }
public void WhenTheDateIsSetToADateThatExceedsTheLimit() { const int DAYS_LIMIT = 30 + 1; _browser.Driver.WaitUntilVisible(CreateHearingPage.HearingDate).Clear(); _browser.Driver.WaitUntilVisible(CreateHearingPage.HearingDate).SendKeys(DateTime.Now.AddDays(DAYS_LIMIT).ToString(DateFormats.LocalDateFormat(_c.Config.SauceLabsConfiguration.RunningOnSauceLabs()))); }
/// <summary> /// DateForFormat /// Prints a Date for given format /// </summary> /// <param name="html"></param> /// <param name="insertedDateTime"></param> /// <param name="dateFormat"></param> /// <returns></returns> public static IHtmlContent DateForFormat(this IHtmlHelper html, DateTime insertedDateTime, DateFormats dateFormat) { if (insertedDateTime == null) { return(HtmlString.Empty); } switch (dateFormat) { case DateFormats.ddMMyyyy: return(new HtmlString(insertedDateTime.Date.ToString("dd/MM/yyyy", new CultureInfo("nl-NL")))); case DateFormats.Unknown: return(HtmlString.Empty); } return(HtmlString.Empty); }