I'm trying to extract activities and the corresponding date and time from the list below. I'm using the shortcut app on iOS for the regex matching.
In the end I want to have the name of the activity and the time for the given weekday (parameter). Testing on https://regex101.com/
If you need more information let me know. Thanks in advance!
UPDATE:
Issue
So the issue is that with the current regex (see below) only activities are shown where the given weekday parameter is followed immediately. In the regex below it will only match
Pilates
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Montag 19:00 - 20:00
Dienstag 17:00 - 18:00
Dienstag 18:00 - 19:00
Donnerstag 11:00 - 12:00
Donnerstag 17:00 - 18:00
Donnerstag 20:00 - 21:00
Freitag 17:00 - 18:00
Samstag 11:00 - 12:00
Samstag 13:00 - 14:00
Sonntag 12:00 - 13:00
Example Code
Mittwoch (Wednesday) added as example, this will be a dynamic variable in the end.
([-\&\sA-zÀ-ÿ]+\n((Mittwoch)\s\d+:\d+\s-\s\d+:\d+\n)+)
Example data
Pilates
Montag 19:00 - 20:00
Dienstag 17:00 - 18:00
Dienstag 18:00 - 19:00
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Donnerstag 11:00 - 12:00
Donnerstag 17:00 - 18:00
Donnerstag 20:00 - 21:00
Freitag 17:00 - 18:00
Samstag 11:00 - 12:00
Samstag 13:00 - 14:00
Sonntag 12:00 - 13:00
Expected Result
Pilates
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Try this Regex.
The regular expression that I use it is this one. Matching only if the name of activitiy is Pilates.
(Pilates\s*)|(Mittwoch [012]\d:[0-5]\d - [012]\d:[0-5]\d\s*)
If the name of the activity is a set of characters then, try this one.
^(\w+\s\s)|(Mittwoch [012]\d:[0-5]\d - [012]\d:[0-5]\d\s*)
As you say, the parameter for this example is Mittwoch, you can change it as your needs.
Hope this help you.
Related
I have a Date Time(Friday, 27 October 2017 4:00:00 AM) in US Central Time zone (CDT). I want to convert this Date Time into different time zones. These are time zones i wanted to convert.
Eastern Time (EDT)
Pacific Time (PDT)
New Delhi, India (IST)
Central Europian Time (CET)
Riyadh, Saudi Arabia (AST)
Pakistan Standard Time (PKT)
Lagos, Nigeria (WAT)
Australian Standard Time (AET)
Greenwich Mean Time (GMT)
Moscow, Russia (MSK)
China Standard Time (CST)
This is how i am doing
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "America/Chicago");
var IST = dateTime.tz('Asia/Calcutta').format('MMMM Do YYYY, h:mm:ss a');
console.log(IST) // October 27th 2017, 9:30:00 am
The returned Date Time is wrong. Because Indian Standard Time is 10 hours and 30 minutes ahead of Central Time.
It should be Friday, 27 October 2017 2:30 PM (IST)
Thanks!
The problem isn't with the conversion to the Indian time zone - it's the original parsing of the Chicago time.
This:
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "America/Chicago");
... is treated as 4am UTC, and then converted to America/Chicago, so it ends up representing 11pm local time (on October 26th) in Chicago. You can see that by just logging the value of dateTime.
If you change the code to:
var dateTime = moment.tz("2017-10-27 04:00:00", "America/Chicago");
... then it's treated as 4am local time on the 27th, which is what I believe you expected. The result of the conversion to Asia/Calcutta is then 2:30pm as you expected.
So either change the format of your input, or specify that format. For example, this works fine too:
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "YYYY-MM-DD h:mm:ss a", "America/Chicago");
Using the tz() function from moment-timezone as follow:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format()
//returns '2017-10-15T13:53:43+08:00'
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format('h:m A')
//I expect to return '9:53 PM' but it returns '1:53 PM'
Ultimately, I want to apply the fromNow() function to format the result. But when I apply it, it uses the initial timestamp and ignore the timezone applied.
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').fromNow()
//I expect to return '1 min ago' when actual time is 13:54 UTC (21:54 in HK) but it returns '8 hours ago'
What am I doing wrong here?
When you do:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong');
You're creating a date/time that corresponds to October 15th 2017, at 1:53 PM in Hong Kong - which, in turn, corresponds to 2017-10-15T05:53:43Z (5:53 AM in UTC).
When you call the format() function:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format();
It returns:
2017-10-15T13:53:43+08:00
The +08:00 part is just the UTC offset - it just tells that Hong Kong is 8 hours ahead UTC. But 2017-10-15T13:53:43+08:00 (1:53 PM in Hong Kong) is exactly the same instant as 2017-10-15T05:53:43Z (5:53 AM in UTC). That's why fromNow(), when the current time is 13:54 UTC, returns 8 hours.
If you want the date/time that corresponds to 1:53 PM in UTC, you should use the utc() function:
// October 15th 2017, 1:53 PM in UTC
moment.utc('2017-10-15 13:53:43');
Now, when the current time is 13:54 UTC, fromNow() will return 1 minute (because the date/time represents 1:53 PM in UTC).
To convert this to Hong Kong timezone, just use the tz() function:
// convert 1:53 PM UTC to Hong Kong timezone (9:53 PM)
moment.utc('2017-10-15 13:53:43').tz('Asia/Hong_Kong').format('h:m A');
This will convert 1:53 PM UTC to Hong Kong timezone (resulting in 9:53 PM):
I'm a bit confused about this outcome, taking today's date minus 2 months, and then taking that date again and adding two months, does not give me today's date when assign the dates to a variable.
Time.zone
"Eastern Time (US & Canada)"
> today = Date.today.in_time_zone
=> Thu, 31 Aug 2017 00:00:00 EDT -04:00
> a = today - 2.months # This is persisted to the db
=> Fri, 30 Jun 2017 00:00:00 EDT -04:00
> b = a + 2.months
=> Wed, 30 Aug 2017 00:00:00 EDT -04:00
If I however, just use the same object, it moves back and forth properly:
> today = Date.today.in_time_zone
=> Thu, 31 Aug 2017 00:00:00 EDT -04:00
> today - 2.months
=> Fri, 30 Jun 2017 00:00:00 EDT -04:00
> today + 2.months
=> Tue, 31 Oct 2017 00:00:00 EDT -04:00
The problem is obviously when "a" gets saved to a database, and then retrieved later on, and calculated plus 2 months..., it should match today's date.
TL;DR
A month is not a fixed duration. Adding or taking a month does not give the same "time shift" depending on which day you are.
The usual algorithm
to add or take months is the following :
try to land on the same day number (4th, 30th, 31st) as you started, just by changing the month
if you would land on an impossible date (like 31th September, 30th February, 29th February for some years) then just go the maximum allowed day number of this month
This implies that adding some months then taking out the same number of months will not necessarily give you back the same date.
Examples :
31st of some month + 1 month --> One would want to get to the 31th of next month
But if there is no 31st of next month (like for 31th of August, no 31st of September), then what to do ?
Usual interpretation would say that you want to go to the end of the month, this is 30th September (for rent or other monthly subscription, for instance)
But usually, 30th of some month - 1 month --> One would want to get to the 30th of the previous month.
That would lead to .... 30th of August. Not 31th of August.
Hence: some date + 1 month - 1 month does not necessarily give the original date !
Another example :
Start at the 30th of August.
Take a month -> 30th of July
Add a month -> You want to get to 30th of August (same number, next month) or to the end of August ?
The default algorithm will try to give the same day number -> 30th of August (which is more logical now)
Also with days...
Note that the same problem happens with days,but much less often ! When some days don't have the same number of hours, for daylight saving days, when adding and taking same number of days you might not get back to the original date and time as you started from.
I want to count the number of the weeks, starting from Friday.
For more explanation: usually the counting starts on Sunday or Monday, but in this case, I want to make it start on Friday.
Some examples:
2nd Jan 2015 (Fri) ~ 8th Jan 2015 (Thu) : 1st week of 2015
...
25th Dec 2015 (Fri) ~ 31st Dec 2015 (Thu) : 52nd week of 2015
1st Jan 2016 (Fri) ~ 7th Jan 2016 (Thu) : 1st week of 2016
...
30th Dec 2016 (Fri) ~ 5th Jan 2017 (Thu) : 53rd week of 2016
6th Jan 2017 (Fri) ~ 12th Jan 2017 (Thu) : 1st week of 2017
What I need to do is
1) to get the week number from the date
ex.
input: Fri, 02 Jan 2015
output: 1
input: Sun, 27 Dec 2015
output: 52
2) to get the date range for the given week number.
I found that .strftime("%V") does almost this, but it counts weeks by every Monday.
Does anyone know nice solution to this?
Here you go:
my_array = Array.new
(Date.today..Date.today.next_year).each do |date|
if date.wday == 5
end_week = date + 6.days
my_array << "#{date.day.ordinalize} #{date.strftime('%b')} #{date.strftime('%Y')} (#{date.strftime('%a')}) ~ #{end_week.day.ordinalize} #{end_week.strftime('%b')} #{end_week.strftime('%Y')} (#{end_week.strftime('%a')}) : #{date.strftime('%U')} week of #{date.strftime('%Y')}"
end
end
# sample output of first element of array
# 30th Oct 2015 (Fri) ~ 5th Nov 2015 (Thu) : 43 week of 2015
Note: You can set any range. here I have set from Today to next year
%U - Week number of the current year, starting with the first Sunday
as the first day of the first week (00..53)
%W - Week number of the current year, starting with the first Monday
as the firstday of the first week (00..53)
for more info: http://apidock.com/rails/ActiveSupport/TimeWithZone/strftime
You can do the variety of operation on the dates here...
DateAndTime
In your case, the below will work for you.
all_week(start_day = Date.beginning_of_week)
I am using Quartz framework, got bit confused with time generation. This is a simple code which generates daily trigger # 11:30 am. To test this out, i generated next 100 consecutive firing time using ComputeFireTimes query but time i get is wierd. May be i m missing something here.
Trigger trig = TriggerUtils.MakeDailyTrigger(11, 30);
var triggerList = TriggerUtils.ComputeFireTimes(trig, null, 100);
foreach (DateTime trigger in triggerList)
{
Console.WriteLine(trigger.ToString());
}
The output i get is
8/12/2011 3:30:00 PM
8/13/2011 3:30:00 PM
8/14/2011 3:30:00 PM
8/15/2011 3:30:00 PM
8/16/2011 3:30:00 PM
8/17/2011 3:30:00 PM
8/18/2011 3:30:00 PM
8/19/2011 3:30:00 PM
The time should have been 11:30 a.m. but it is showing 3:30 pm.
These are UTC (GMT) times, maybe your time zone is 4 hours different
from UTC? You would need to change the display to your local time zone
by calling Console.WriteLine(trigger.ToLocalTime().ToString());