I am trying to build an Alexa skill that asks the user for an arrival time and I am expecting the answer to be in 24 hour format. So the user would say eighteen o five for 18:05.
I am struggling to find a way for Alexa to understand this without forcing the user down the 12 hour route.
Any suggestions welcome.
The AMAZON.TIME slot type is available but, unfortunately, doesn't work like you want.
If you're happy for users to say "six fifteen pm" it will pass a 24H time to your skill.
This might be unconventional, but have you tried
AMAZON.FOUR_DIGIT_NUMBER
If you think about it 24 hour format is also a 4 digit number
I got around this in the end by using just the one custom slot type which takes the whole time in a malformed state. 18:05 comes in as 18o5. I then use a method within my code to tidy that up. Not the most scientific way to do this, but seems to work.
Related
What I want to do is block a user from doing something for 24 hours after they have reached a limit. I have coded the limit part, I just need to know how to block it if it hasn't been 24 hours.
Here is an example on how I want to do it. Update the user's account using a query and set the timestamp (Unix) to that time. Then I don't know how I can get another timestamp of the time they try to do it and check if the new timestamp is 24 hours between the last?
I have medium experience with C# but timestamps is one section I know nothing about with c#. Ss there anyone here that can help or provide a good tutorial? Or an idea on how I can learn more about it. I'm looking for the best way to do this. If Unix timestamps aren't it then please let me know and provide me with a better way if you can.
//Example
if (!CODE_HERE_FOR_NOT_24_HOURS)
{
MessageBox.Show("You have reached your limit for today. Try again tomorow");
return;
}
else
{
//Code here
}
In C#, you'd typically use DateTime.UtcNow, and use a DateTime, not a unix timestamp.
You can always check to see if its been less than 24 hours via:
if (timeStamp > DateTime.UtcNow.AddDays(-1))
{
// It's been less than 24 hours
}
I am working on an application that needs to set rules for periods of time. The company has different branches, each branch can set its own rules (i.e a branch starts work at 8.30 am, ends work at 17.30 pm, with 30 minutes pause for lunch; another branch start at 9.00, ends at 19.00 with 1 hour pause...)
So I need to define a class (let's call it WorkingDayDefinition for the moment) where start and end are not actually a DateTime, because they are not referred to any specific day in particular.
At the moment the only option I see in C# is using Timespan for setting a duration from the beginning of the day, so that 8.30 pm would be TimeSpan(8,30,0) to be added to the Day part of whichever day.
Is this a best practice in C#?
I searched for third parties libraries that could help me, but so far my best bet is this one:
http://www.codeproject.com/Articles/168662/Time-Period-Library-for-NET
that is not strictly what I need
You could use Noda Time. It provides a LocalTime (see here):
LocalTime is an immutable struct representing a time of day, with no reference to a particular calendar, time zone or date.
For 8.30 you would do something like:
LocalTime openingAt = new LocalTime(8, 30);
To me TimeSpam seems very suitable for what you want. It holds an interval of time, sometimes between two events, but in your case between the start of the day and the time you start/finish work. There is no reason I can think of not to use it just because the name might suggest this wasn't the original intention of the class. Plus it already integrates well with DateTimes for any time calculations you need to do later on down the road.
I'm currently writing a fairly simple app handling opening/closing times of businesses and running into serious difficulties trying to figure out how to properly store the info.
Most of our critical functionality is heavily dependent on getting times absolutely perfect, so obviously I want to get things done the best way possible to start off with!
Additionally, the data will be inputted by users, so if the underlying representation is slightly more complex (e.g. using TimeSpans to account for opening past midnight), this needs to be invisible to the user.
I need to store firstly, the business's opening hours, by day of week, with a timezone associated with them, e.g:
- M: 1000 - 2330
- T: 1000 - 0030
- W: 1900 - 0300
- Th: 2000 - 0300
- F: 2000 - 0800
- Sa: 1000 - 0500
- Su: 1000 - 2300
I'm currently thinking that the best way to store this is using a class like this:
public class OpeningHours
{
ZonedDateTime OpeningTime { get; set; }
Period durationOpen { get; set; }
// TODO: add a method to calculate ClosingTime as a ZonedDateTime
}
However, there's 2 main complications here:
I don't want to store the Year, Month, or Date part of the ZonedDateTime - I just care about the DayOfWeek.
Sure, I could just store each value as the first Monday/Tuesday etc after Jan 1 1970, but this seems hacky and pretty much plain wrong - as the author of NodaTime, very correctly, explains here when talking about the limitations of the BCL DateTime implementation. I also have a feeling this would probably end up with weird quirky bugs if later on we try and do any arithmetic with the dates.
The user is going to have to input the ClosingTime anyway. Client side I suppose I could do something simple like always assume the ClosingTime is the next day if it's before the OpeningTime, but again, it's not perfect, and also doesn't account for places that might be open for more than 24 hours (e.g. supermarkets)
Another thing I've considered is using a table with hours/days and letting people highlight the hours of the week to pick opening times, but you still run into the same problem with only wanting to store the DayOfWeek part of the OpeningTime.
Any suggestions would be appreciated, spending the last 6 hours reading about the hilariously silly ways we humans represent time has burnt me out a bit!
I would strongly consider using LocalTime instead of ZonedDateTime, for a couple of reasons:
You're not trying to represent a single instant in time; these are naturally recurring patterns (there's no associated date)
You're not trying to cope with the situation where the store is in different time zones for different opening hours; you probably want to associate a time zone with each store once, and then you can apply that time zone whenever you want
So I would have something like this (showing just the data members; how you sort out the behaviour is a separate matter):
public class StoreOpeningPeriod
{
IsoDayOfWeek openingDayOfWeek;
LocalTime openingTime;
LocalTime closingTime;
}
Note that this exactly follows your original data as you've shown it, which is always a good sign - you're neither adding nor losing information, and it's presumably in a convenient form.
If the closing time is earlier than the opening time, it's assumed that this crossed midnight - you might want to add a confirmation box for the user if this is relatively uncommon, but it's certainly easy to spot and handle in code.
I'm looking for a way to format time duration originally expressed in hours (as a 'double' variable) for an ASP.NET web app written in C#. I need a short version that has only 2 significant values. For instance:
1h:20m
2d:20h
2mo:12d
5y:2mo
I searched and it seems like C# does not have a built-in function for what I need.
So I decided to write my own but I'm stumped with correct formatting of all the parts. For instance, I may get a string, such as "1d:24h", or for a simple 2 months, I may get "1mo:29d"
PS. The problem I've encountered is in defining how many days are in a month and in a year.
DateTime's are renowned for being an annoying task.
As there is no indication as to which months you are referring to, with the given information this would be impossible. Months can have 28, 29, 30 and 31 days depending on what month/year you are taking into consideration..
Without an indication as to which months you are dealing with, the flip from 1 to 2 months would be a random guess as to which day you make the transition. You will either have to add in more incoming parameters to account for this, or explain to the user that a month is considered x days and only x days.
Another thing to consider would be daylight savings. 1pm + 24 hours may not be 1pm the next day. In such circumstances with you or the end user may wish to consider such days 23h=1d or 25h=1d.
I know the title might be confusing, but I'm not sure how to word it better....
I'm doing this to get the logs of the current hour:
'TraceSink-'yyyy-MM-dd HH'-Hourly.log'
How can I get the previous hour? i.e.:
'TraceSink-'yyyy-MM-dd (HH-1)'-Hourly.log'
Is there anything possible with time format like that?
EDIT: I don't have access to the C# code but a exe.config where I can change what goes inside.
Like var on DateTime.ToString(var);
Am I asking too much?
Subtract one hour from the date/time and format that.
The answer to your question is no.
The format string only defines the format. It does not have the ability to perform calculation on it (and why would it?)
I don't know why you have this requirement, but I suspect that you may be receiving DateTime objects from a machine in another time zone... it could be helpful if you included the offset from UTC in your format string:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#zSpecifier
This way, when you see the log you can tell that the specific event occurred at UTC -3 hours.
I think that's the best you can do without access to the original code.