I am new in Laravel and using 5.5 ver. I have two input field star_time and end_time
Start time Input Value is : 10:00AM
End Time Input value is: 01:00PM
this is my validation rule
$validator = Validator::make($request->all(),[
'start_time' => 'required|date_format:H:iA',
'end_time'=>'required|date_format:H:iA|after:start_time',
]);
every time given "The end time does not match the format H:iA"
Please help how to validate start time and end time and end time bigger than start time and time format with am/pm
This is late answer to you question but here is solution for it. just write H as h in you validator.
$validator = Validator::make($request->all(),[
'start_time' => 'required|date_format:h:iA',
'end_time'=>'required|date_format:h:iA|after:start_time',
]);
You should use h instead of H as you are using A for AM and PM.
H work for 24 hours
h work for 12 hours
A (use upercase) work for AM or PM
Related
Here's the code:
# Scrape table data
alltable = driver.find_elements_by_id("song-table")
date = date.today()
simple_year_list = []
complex_year_list = []
dateformat1 = re.compile(r"\d\d\d\d")
dateformat2 = re.compile(r"\d\d\d\d-\d\d-\d\d")
for term in alltable:
simple_year = dateformat1.findall(term.text)
for year in simple_year:
if 1800 < int(year) < date.year: # Year can't be above what the current year is or below 1800,
simple_year_list.append(simple_year) # Might have to be changed if you have a song from before 1800
else:
continue
complex_year = dateformat2.findall(term.text)
complex_year_list.append(complex_year)
The code uses regular expressions to find four consecutive digits. Since there are multiple 4 digit numbers, I want to narrow it down to between 1800 and 2021 since that's a reasonable time frame. simple_year_list, however, prints out numbers that don't follow the conditions.
You aren't saving the right value here:
simple_year_list.append(simple_year)
You should be saving the year:
simple_year_list.append(year)
I would need more information to help further though. Maybe give us a sample of the data you're working through, and the output you're seeing?
You can do it all in regex.
Add start ^ and end $ anchors, and range restriction via pattern:
dateformat1 = re.compile(r"^(1[89]\d\d|20([01]\d|2[01]))$")
My server is in UTC time.
I create a localized date time in Los Angeles with moment like this:
var m = moment.tz('2021-04-13T20:30:53-07:00', 'America/Los_Angeles');
This part works great. Doing m.date() gives me 13. However I need to give it to a lib as a Date object, not a Moment so what I do is:
var d = m.toDate()
However now my server gets the wrong day. As it's in UTC it does d.getDate() which gives it the 14th, as UTC is 7 hours ahead so this timestamp is 3:30am.
Is there a way in moment to get the unzoned date? Such that even in UTC d.getDate() will give 13th.
I wrote this custom function, but I was hoping the moment-timezone lib provided this.
const getUnzonedDate = (m) => {
return m.clone().add(m.utcOffset(), 'minutes').toDate();
}
Another example
The above getUnzoned date works if my system time is in UTC. Let's say my system time is in LA:
* Removes zone information means, if system time is LA:
*
* const m = moment.tz('2021-04-13T21:30:53', 'America/New_York');
* m.hours() === m.toDate().getHours(); // false
* m.hours() === getUnoznedDate(m).getHours(); // true
*
* So it means that when the date will give you same numbers for each unit in
* moment and as a date.
Is there a way to get the current date in ballerina?
As I was browsing through some code examples I came across the syntax to get the current time. Shown below is how to get the current date in Ballerina:
Note: first you have to import the time package given below for this to work.
import ballerina/time;
Then put the following lines of code:
time: Time currentTime = time:[currentTime][2]();
string customTimeString = currentTime.format("dd-MM-yyyy");
This will give the following output:
08-07-2018
This is work for ballerina 0.991 and 1.0 first you have to import the time package
Then it will give the current date if you want to get in a format it will included the code
import ballerina/time;
To get current time
time:Time time = time:currentTime();
string standardTimeString = time:toString(time);
io:println("Current system time in ISO format: ", standardTimeString);
To format the time
string|error customTimeString = time:format(time, "yyyy-MM-dd-E");
if (customTimeString is string) {
io:println("Current system time in custom format: ", customTimeString);
}
y -Years
M -months
d -date
E -day
h -hour
m -Minuit
s -seconds
For Swan Lake Update 3 they seem to have removed the time:currentTime() function.
It seems they have replaced it with time:utcNow().
According to the ballerina documentation,
"The time:Utc is the tuple representation of the UTC. The UTC represents the number of seconds from a specified epoch. Here, the epoch is the UNIX epoch of 1970-01-01T00:00:00Z."
So you can convert this above tuple representation to RFC 3339 timestamp by using,
time:Utc currTime = time:utcNow();
string date = time:utcToString(currTime);
io:println(date);
Then you will get a result like below,
2023-01-14T17:04:15.639510400Z
Using ballerina time library you can convert to other different representations as well.
Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression?
I've got a form where users can input a copyright date (as a string), and these are the allowed formats:
Year: YYYY (eg 1997)
Year and month: YYYY-MM (eg 1997-07)
Complete date: YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes: YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds: YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
I don't have much experience of writing regular expressions so if there's an easier way of doing it I'd be very grateful!
Not thoroughly tested and hence not foolproof, but the following seems to work:
var regex:RegExp = /(?<=\s|^)\d{4}(-\d{2}(-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{2})?)?\+\d{2}:\d{2})?)?)?(?=\s|$)/g;
var test:String = "23 1997 1998-07 1995-07s 1937-04-16 " +
"1970-0716 1993-07-16T19:20+01:01 1979-07-16T19:20+0100 " +
"2997-07-16T19:20:30+01:08 3997-07-16T19:20:30.45+01:00";
var result:Object
while(result = regex.exec(test))
trace(result[0]);
Traced output:
1997
1998-07
1937-04-16
1993-07-16T19:20+01:01
2997-07-16T19:20:30+01:08
3997-07-16T19:20:30.45+01:00
I am using ActionScript here, but the regex should work in most flavors. When implementing it in your language, note that the first and last / are delimiters and the last g stands for global.
I'd split the input field into many (one for year, month, day etc.).
You can use Javscript to advance from one field to the next once full (i.e. once four characters are in the year box, move focus to month) for smoother entry.
You can then validate each field independently and finally construct the complete date string.
I have scratched my brains enough to find my last resort here . I am calling an API which takes values like below for the lastUpdatedTime paramter :
lastUpdatedTime : 1499591547769
lastUpdatedTime : 1499591547770
So i assume the above values are converted to miliseconds since there are 13 digits (1499591547770 & 1499591547769).
Below is what i want to do in simple english .
Get the UTC time now and subtract 15 minutes from it .
Send that value to the API and fetch the data.
My problem is time conversion .
Below is what i am doing in python.
update_time = (datetime.utcnow() - timedelta(minutes=15)).strftime('%m/%d/%Y %H:%M:%S')
update_time_check = (calendar.timegm(time.strptime(update_time, '%m/%d/%Y %H:%M:%S')))*1000
The value for the above is something like 1502247759000
When i send that value (lastUpdatedTime = 1502247759000) to the API , i get a blank result set .
Please let me know if my steps are correct in generating the timestamp which the API is expecting .
Thanks in advance.