Browsing 7239 questions and answers with Jon Skeet

Equivalent of org.eclipse.jetty.server.Connector.getLocalPort() in Jetty 9.x

In Jetty 8.1.17.v20150415 I am using the org.eclipse.jetty.server.Connector.getLocalPort() method to determine which random HTTP port my Jetty is listening on, using the following...
Jon Skeet
people
quotationmark

It looks like that's now in NetworkConnector (which extends Connector) - presumably because some connectors don't run over a network. If you know that your server will be using a NetworkConnector, you could presumably... more 9/25/2015 10:44:35 AM

people

Cast to char while toggline string case without using inbuilt functions

Here is the program i have written for converting case of string. However i am getting a compilation error as i have commented in the following program. Can you please explain to...
Jon Skeet
people
quotationmark

As the compiler says, you're trying to assign an int value (the result of a[i] + 32 for example to a char variable (a[i]). The "surprise" part here is that the result of a[i] + 32 is a char... but it's only a surprise if you don't look at... more 9/25/2015 10:24:29 AM

people

Add minutes to date during time changing

I want to add minutes to date where time is changing. Eg. In 24-10-2015 time at 3 o'clock time goes back one hour in the back. So when we have 2:20 AM, 50 minutes later we have...
Jon Skeet
people
quotationmark

This sort of thing is precisely why I started the Noda Time project. It teases out assumptions you might have. For example, in your example, 2:20am occurs twice - so when you say new DateTime(2015,10,24, 2,20, 00) how is the system meant... more 9/25/2015 9:34:22 AM

people

Conversion from UTC to IST returning same value in JAVA using Joda time library

I need to convert TimeZone in my project from UTC to IST and vice versa. For that purpose I am using Joda time jar in my project. But the problem occurs when I try to convert the...
Jon Skeet
people
quotationmark

There are two problems here. Firstly, when you're parsing the value you're not specifying the time zone - so it's using your local time zone. Secondly, you're not using any formatter for the result - you're just calling... more 9/25/2015 7:55:57 AM

people

Checking for a Day Change Timezone Adjusted

I just took a stab at creating some code (pasted below) that would check for a day change. However, now I'm reading that there's a special function for day...
Jon Skeet
people
quotationmark

The documentation (which was slightly harder to locate than I'd have hoped, admittedly) is reasonably clear: Posted whenever the calendar day of the system changes, as determined by the system calendar, locale, and time zone. So... more 9/25/2015 7:48:29 AM

people

Converting string to pointer syntax

This compiles: string s = "my string"; unsafe { fixed (char* ptr = s) { // do some works } } This does not: string s = "my...
Jon Skeet
people
quotationmark

It's in section 18.6 of the spec - the fixed statement. The relevant productions are: fixed-statement:   fixed ( pointer-type fixed-pointer-declarators ) embedded-statement fixed-pointer-declarator:   ... more 9/24/2015 7:58:30 PM

people

Check if XElement contains specific child node

Perhaps I am going about this wrong, but I have an XElement storing an XML object like this <call> <attempted/> <completed> <welcomecall/> ...
Jon Skeet
people
quotationmark

If you don't mind whether or not it's within a completed element, you could just use: var hasWelcomeCall = call.Descendants("welcomecall").Any(); If it can be within any one of a number of completed elements, but you want to check that... more 9/24/2015 7:17:28 PM

people

Is there a way to define a time interval in C#?

I want to define a time interval and check if System.DateTime.Now is within that interval. Is there a way to do that? It seems you can only define a specific time using...
Jon Skeet
people
quotationmark

Firstly, I wouldn't use DateTime.Now - you should almost certainly be using DateTime.UtcNow, assuming you really want it to be an interval of elapsed time rather than local time. An interval of local time could lead to some really weird... more 9/24/2015 6:46:41 PM

people

How to Parse a Date Time with TimeZone Info

I have following string , Thu Sep 24 2015 00:00:00 GMT+0530 (IST) I tried with following but it's faling. var twDate = DateTime.Parse("Thu Sep 24 2015 00:00:00 GMT+0530...
Jon Skeet
people
quotationmark

You need to trim the time zone abbreviation off using normal string operations, then specify a custom date and time format string. For example: // After trimming string text = "Thu Sep 24 2015 00:00:00 GMT+0530"; var dto =... more 9/24/2015 3:10:26 PM

people

Elegant way of converting between StringComparison and StringComparer?

Some .NET methods use StringComparison as parameter, some use StringComparer (often in form of IComparer). The difference is clear. Is there some elegant way how to get...
Jon Skeet
people
quotationmark

Going from StringComparison to StringComparer is simple - just create a Dictionary<StringComparison, StringComparer>: var map = new Dictionary<StringComparison, StringComparer> { { StringComparison.Ordinal,... more 9/24/2015 2:34:19 PM

people