Пример #1
0
        ///// <summary>
        /////
        ///// </summary>
        //public static string FromJulian
        //    (
        //        long julianDate,
        //        string format
        //    )
        //{
        //    long L = julianDate + 68569;
        //    long N = (long)(4 * L / 146097);
        //    L = L - (long)((146097 * N + 3) / 4);
        //    long I = (long)(4000 * (L + 1) / 1461001);
        //    L = L - (long)(1461 * I / 4) + 31;
        //    long J = (long)(80 * L / 2447);
        //    int Day = (int)(L - (long)(2447 * J / 80));
        //    L = (long)(J / 11);
        //    int Month = (int)(J + 2 - 12 * L);
        //    int Year = (int)(100 * (N - 49) + I + L);

        //    // example format "dd/MM/yyyy"
        //    return new DateTime(Year, Month, Day).ToString(format);
        //}

        /// <summary>
        ///
        /// </summary>
        public static string FromJulianDate
        (
            DateTime gregorian
        )
        {
            JulianCalendar calendar     = new JulianCalendar();
            var            dateInJulian = calendar.ToDateTime
                                          (
                gregorian.Year,
                gregorian.Month,
                gregorian.Day,
                gregorian.Hour,
                gregorian.Minute,
                gregorian.Second,
                gregorian.Millisecond
                                          );

            return(dateInJulian.ToString("yyyyMMdd"));
        }
Пример #2
0
        public static string ParseFileName(string input, string payeeID)
        {
            {
                string output = "";
                try
                {
                    string[] stringParts = input.Split('#');

                    bool parameterFound = false;
                    foreach (string stringPart in stringParts)
                    {
                        if (stringPart == "")
                        {
                            if (parameterFound)
                            {
                                output += "#";
                            }
                            else
                            {
                                parameterFound = true;
                            }
                        }
                        else if (parameterFound)
                        {
                            // Parameter Could have two parts separated by pipe (|)
                            // First Part tells the name of the parameter
                            // Second Part tells the format to be used for the given parameter
                            string[] strPart = stringPart.Split('|');
                            switch (strPart[0].ToUpper())
                            {
                            case "HOSTNAME":
                                output        += Dns.GetHostName();
                                parameterFound = false;
                                break;

                            case "PAYEE_ID":
                                output        += payeeID;
                                parameterFound = false;
                                break;

                            case "DATE":
                                string dateFormat = string.Empty;
                                if (strPart.Length == 2)
                                {
                                    dateFormat = strPart[1];
                                }
                                if (String.IsNullOrEmpty(dateFormat) || (strPart.Length != 2))
                                {
                                    throw new InvalidOperationException(String.Format("Invalid Date format[{0}] passed in file name [{1}] ", stringPart, input));
                                }
                                output        += DateTime.Now.ToString(dateFormat);
                                parameterFound = false;
                                break;

                            case "JULIAN_DAY":
                                JulianCalendar calendar     = new JulianCalendar();
                                DateTime       dateInJulian = calendar.ToDateTime(DateTime.Today.Year,
                                                                                  DateTime.Today.Month,
                                                                                  DateTime.Today.Day,
                                                                                  DateTime.Today.Hour,
                                                                                  DateTime.Today.Minute,
                                                                                  DateTime.Today.Second,
                                                                                  DateTime.Today.Millisecond);

                                int julianDay = calendar.GetDayOfYear(dateInJulian);
                                output        += Convert.ToString(julianDay);
                                parameterFound = false;
                                break;

                            default:
                                output += "#" + stringPart;
                                break;
                            }
                        }
                        else
                        {
                            output        += stringPart;
                            parameterFound = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //_logger.ErrorFormat("Failed to parse file name [{0}]. Error: {1}", input, ex.ToString());
                    throw;
                }
                return(output);
            }
        }