Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:23:14+00:00 2026-06-06T11:23:14+00:00

Currently, I’m returning feedback to the user in this form: <UserName> removed 07:00, 07:15,

  • 0

Currently, I’m returning feedback to the user in this form:

"<UserName> removed 07:00, 07:15, 07:30, 07:45, 08:00, 08:15, 08:30, 09:00, 09:15, 09:30, 09:45, 10:00, 10:15, 10:30, 11:15, (etc.)"

…Understandably, they want it to be more user-friendly, such as this instead:

<UserName> removed 07:00 - 8:30, 9:00 - 10:30, 11:15 - (etc.)

Rather than rework the whole method that concatenates these values into a StringBuilder, I’d like to take that first output and morph it into the second; something like:

sbQuarterHoursRemoved = CombineSucceedingQuarterHours(sbQuarterHoursRemoved);

Is this as tedious as it appears to me, or does somebody know a relatively painless way of accomplishing it?

UPDATE

I adapted the code below to this:

String QuarterHoursRemovedPrettified = PrettifyQuarterHoursRemoved(sbQuarterHoursRemoved);
. . .

private static string PrettifyQuarterHoursRemoved(StringBuilder sbQuarterHoursRemoved)
{
    string[] times = sbQuarterHoursRemoved.ToString().Split(',');
    DateTime prevDt = new DateTime(1);
    string prevString = "";

    StringBuilder output = new StringBuilder();
    foreach (string time in times) {
        DateTime dt = DateTime.ParseExact(time, "HH:mm", CultureInfo.InvariantCulture);
        if (dt.Subtract(prevDt).TotalMinutes > 15) {
            if (prevString != "")
                output.Append(" " + prevString + ",");
            output.Append(" " + time + " -");
        }
        prevString = time;
        prevDt = dt;
    }
    output.Remove(output.Length - 1, 1);
    return output.ToString(); 
}

With values in times like this (after the call to Split()):

00:45
01:00
01:15
22:45
23:00

It ALWAYS crashes the second pass through the loop. The first goes fine, but the second time, no matter what value, crashes.
e.g., the first time through, dt becomes:

dt = 6/26/2012 12:45 am

…after the call to ParseExact()

…but the second call to ParseExact() – with, for example, “01:00” as the value in “time” fails.

Some error details are:

*System.FormatException was unhandled
Message=String was not recognized as a valid DateTime.
Source=mscorlib
StackTrace:
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style)
at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
at TitanNextGen_Platypi.PlatypiMainForm.PrettifyQuarterHoursRemoved(StringBuilder sbQuarterHoursRemoved) in…*

UPDATED AGAIN

It works now – untrimmed vals were the problem. When the value was, for example, ” 01:15″ instead of “01:15” all Dallas broke loose (and I changed “hh:mm” to “HH:mm” in the call to ParseExact() to account for 24-hour time)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:23:15+00:00Added an answer on June 6, 2026 at 11:23 am

    As you are processing the strings, you will need to keep track of where you are at and if you need to start a new sequence:

        string[] times = { "07:00", "07:15", "07:30", "07:45", "08:00", "08:15", "08:30", "09:00", "09:15", "09:30", "09:45", "10:00", "10:15", "10:30", "11:15" };
    
        private void Form1_Load(object sender, EventArgs e)
        {
            DateTime prevDt = new DateTime(1);
            string prevString = "";
    
            StringBuilder output = new StringBuilder("UserXyz Deleted ");
            foreach (string time in times)
            {
    
                DateTime dt = DateTime.ParseExact(time,"hh:mm", CultureInfo.InvariantCulture);
                if (dt.Subtract(prevDt).TotalMinutes > 15)
                {
                    if (prevString != "")
                        output.Append(" " + prevString + ",");
                    output.Append(" " + time + " -");
                }
                prevString = time;
                prevDt = dt;
            }
            output.Remove(output.Length - 1, 1);
            MessageBox.Show(output.ToString());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, Django 1.2.3 User model unicode is def __unicode__(self): return self.username and I'd like
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache
Currently, I have something like: public partial class Form1 : Form { delegate void
Currently I am debugging the signing of an Android app. And this would be
Currently, most of the popular websites, like google, yahoo detect if the user connection
I want use html5's new tag to play a wav file (currently only supported
Currently It just opens up the xml, but i want to get a dialog
Currently I have alot of information that are in several different divs. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.