I am trying to use it in my code after using DatePicker but no suggestions are coming for NSDateFormatter and only DateFormatter is coming.
If anyone has used in their code, kindly share it here.
Also, what changes should i make in order to receive the suggestions.
I want to change the format from MM-DD-YYYY to DD-MM-YYYY.
Swift 3 has dropped NS prefix, so you wont get suggestion for NSDateFormatter. DateFormatter is same as NSDateFormatter, just the name is changed. You can use DateFormatter in same way you have been using NSDateFormatter. Check SE-0086 proposal for more details.
try this
let dateFormatter = DateFormatter()
//format in which recived Date Present
dateFormatter.dateFormat = "dd-MMM-yyyy"
let newDate = dateFormatter.date(from: "20-MAR-2017")
// format to which you need your date to convert
dateFormatter.dateFormat = "MMM-dd-yyyy"
if let newDate = newDate{
let dateStr = dateFormatter.string(from: newDate)
print(dateStr) //Output: MAR-20-2017
}
Related
I'd just like to know whether there's a bug in macOS or if I have to make changes in code with currency formatted TextFields.
My problem: just a simple TextField in SwiftUI like
TextField("amountOnDeadline",value: $startValue, formatter: Formatters.currencyFormatter)
The formatter ist pretty simple:
static let currencyFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.maximumFractionDigits = 2
return formatter
}()
Build and run!
The offered field is displayed as currency field. Great! But when I enter a number like 123, the field is reset to 0.00 € (or the value displayed on start).
Only when I exactly mark the 0.00 without the currency symbol and enter a value, the new value is taken.
This is not very user friendly. Is it something I have to live with or is there a solution for this problem? e.g. a special config in NumberFormatter.
Instead of using NumberFormatter you can use currency(code:) FormatStyle with TextField init(_:value:format:prompt:).
TextField("amountOnDeadline",value: $startValue, format: .currency(code: Locale.current.currencyCode ?? "EUR"))
This will not reset the field to 0.00 even if you remove the currency symbol.
I am not good at using regex and struggling to make a regex that will get data from new line after the semicolon. For example, look at this example
Regarding:
267 Covert St Rm 3.5
Contact Information:
(869) 869-5365 <8698695365>
abc#gmail.com
Comments:
I'd like to schedule a viewing for Covert St #3.5, Brooklyn, NY 11207, US.
Please contact me with more information! I am available at
abc#gmail.com
From the above text, I need to get texts under Regarding, contact Information, and comments.
I have made this regex but It is getting whole string
regExp = new RegExp("(?<=Regarding:)(\n).*");
I am making a script in google apps script and parsing data from an email.
Thanks.
I'm not sure if is need RegExp in this case. It can be just splitted:
var s = `Regarding:
267 Covert St Rm 3.5
Contact Information:
(869) 869-5365 <8698695365>
abc#gmail.com
Comments:
I'd like to schedule a viewing for Covert St #3.5, Brooklyn, NY 11207, US.
Please contact me with more information! I am available at
abc#gmail.com`
var regarding = s.split("Regarding:")[1].split("Contact Information:")[0];
console.log(regarding);
var contacts = s.split("Contact Information:")[1].split("Comments:")[0];
console.log(contacts);
var coments = s.split("Comments:")[1];
console.log(coments);
If you need just one first line after : here you go:
var s = `Regarding:
267 Covert St Rm 3.5
Contact Information:
(869) 869-5365 <8698695365>
abc#gmail.com
Comments:
I'd like to schedule a viewing for Covert St #3.5, Brooklyn, NY 11207, US.
Please contact me with more information! I am available at
abc#gmail.com`
var regarding = s.split("Regarding:\n")[1].split('\n')[0];
console.log(regarding);
var contacts = s.split("Contact Information:\n")[1].split('\n')[0];
console.log(contacts);
var coments = s.split("Comments:\n")[1].split('\n')[0];
console.log(coments);
But your regExp gives about the same result:
var s = `Regarding:
267 Covert St Rm 3.5
Contact Information:
(869) 869-5365 <8698695365>
abc#gmail.com
Comments:
I'd like to schedule a viewing for Covert St #3.5, Brooklyn, NY 11207, US.
Please contact me with more information! I am available at
abc#gmail.com`
var regExp = new RegExp("(?<=Regarding:)(\n).*");
var r = s.match(regExp)[0];
console.log(r);
var regExp = new RegExp("(?<=Contact Information:)(\n).*");
var c = s.match(regExp)[0];
console.log(c);
var regExp = new RegExp("(?<=Comments:)(\n).*");
var cm = s.match(regExp)[0];
console.log(cm);
So, what your problem is, after all?
Actually, regex is the way to go here. This snippet does the job and the result array contains all three paragraphs:
const str =
`Regarding:
267 Covert St Rm 3.5
Contact Information:
(869) 869-5365 <8698695365>
abc#gmail.com
Comments:
I'd like to schedule a viewing for Covert St #3.5, Brooklyn, NY 11207, US.
Please contact me with more information! I am available at
abc#gmail.com`;
const re = /(?<=:(\n|^)).*?(?=\n\n|$)/gis;
const result = str.match(re);
console.log(JSON.stringify(result, null, 2));
I have a big txt file which includes chat transcripts, My goal would be extract different components and create a Pandas Df to store in it. A sample of the chat is as below:
*****************************************************
Session:123456
Chat Date: 2017-05-01T08:01:45+00:00
Chat exec name: Sam
Member name: Sara
2017-05-01T08:01:45+00:00 Sara: I need help on element A
2017-05-01T08:01:47+00:00 Sam: Sure I can help you on this one
2017-05-01T08:01:48+00:00 Sara: Is there a better product
2017-05-01T08:01:48+10:00 Sam: Sure we have a lot of new products
2017-05-01T08:01:49+18:00 Sara: Can you let me know
2017-05-01T08:01:51+20:00 Sam: Here is the solution
2017-05-01T08:01:52+00:00 Sara: Thanks for this
2017-05-01T08:01:52+11:00 Sam: Have a Nive day Bye!!
*****************************************************
Session:234567
Chat Date: 2017-05-02T18:00:30+00:00
Chat exec name: PAUL
Member name:CHRIS
2017-05-02T18:00:30+00:00 CHRIS: I need help on element A
2017-05-02T18:02:30+00:00 PAUL: Sure I can help you on this one
2017-05-02T18:02:39+00:00 CHRIS: Is there a better product
2017-05-02T18:04:01+00:00 PAUL: Sure we have a lot of new products
2017-05-02T18:04:30+00:00 CHRIS: Can you let me know
2017-05-02T18:08:11+00:00 PAUL: Here is the solution
2017-05-02T18:08:59+00:00 CHRIS: Thanks for this
2017-05-02T18:09:11+00:00 PAUL: Have a Nice day Bye!!
*****************************************************
If I am able to create a table with the columns:
Session, ChatDate, ChatExecName, Membername, Time, Person, Sentence
The first 4 columns should be repeated for the complete block of chat. besides the delimiters are fixed and they never change.
I have tried this but this returns all blocks together can somebody please help.
import re
def GetTheSentences(infile):
Delim1 = '*****************************************************'
Delim2 = '*****************************************************'
with open(infile) as fp:
for result in re.findall('Delim1(.*?)Delim2', fp.read(), re.S):
print (result)
and
import re
def GetTheSentences2(file):
start_rx =re.compile('*****************************************************')
end_rx = re.compile('*****************************************************')
start = False
output = []
with open(file, encoding="latin-1") as datafile:
for line in datafile.readlines():
if re.match(start_rx, line):
start = True
elif re.match(end_rx, line):
start = False
if start:
output.append(line)
print (output)
I sure hope this is helpful:
data = '''*****************************************************
Session:123456
Chat Date: 2017-05-01T08:01:45+00:00
Chat exec name: Sam
Member name: Sara
2017-05-01T08:01:45+00:00 Sara: I need help on element A
2017-05-01T08:01:47+00:00 Sam: Sure I can help you on this one
2017-05-01T08:01:48+00:00 Sara: Is there a better product
2017-05-01T08:01:48+10:00 Sam: Sure we have a lot of new products
2017-05-01T08:01:49+18:00 Sara: Can you let me know
2017-05-01T08:01:51+20:00 Sam: Here is the solution
2017-05-01T08:01:52+00:00 Sara: Thanks for this
2017-05-01T08:01:52+11:00 Sam: Have a Nive day Bye!!
*****************************************************
Session:234567
Chat Date: 2017-05-02T18:00:30+00:00
Chat exec name: PAUL
Member name:CHRIS
2017-05-02T18:00:30+00:00 CHRIS: I need help on element A
2017-05-02T18:02:30+00:00 PAUL: Sure I can help you on this one
2017-05-02T18:02:39+00:00 CHRIS: Is there a better product
2017-05-02T18:04:01+00:00 PAUL: Sure we have a lot of new products
2017-05-02T18:04:30+00:00 CHRIS: Can you let me know
2017-05-02T18:08:11+00:00 PAUL: Here is the solution
2017-05-02T18:08:59+00:00 CHRIS: Thanks for this
2017-05-02T18:09:11+00:00 PAUL: Have a Nice day Bye!!
*****************************************************'''
data = data.split('*****************************************************')
data = [item.split('\n') for item in data if item]
result = []
for group in data:
group = [item for item in group if item]
times = []
people = []
lines = []
for item in group:
if item.startswith('Session'):
session = item.split(':')[-1]
print session
elif item.startswith('Chat Date'):
chatDate = item.split(':', 1)[-1]
elif item.startswith('Chat exec'):
execName = item.split(':')[-1]
elif item.startswith('Member'):
memberName = item.split(':')[-1]
else:
times.append(item[:25])
people.append(item[26:].split(':')[0])
lines.append(item[26:].split(':')[-1])
for i in range(len(times)):
result.append([session, chatDate, execName, memberName, times[i], people[i], lines[i]])
import pandas as pd
df = pd.DataFrame(result, columns=['Session', 'ChatDate', 'ChatExecName', 'Membername', 'Time', 'Person', 'Sentence'])
print df
I have a DatePicker in ExtJS4. I only want to allow TWO dates for each month. The 15th and last day (30/31/28/29 depending on month/year)
How can I disable every day in the picker but allow those two dates?
See disabledDates config option for Ext.form.field.Date
From API docs:
disabledDates : String[] An array of "dates" to disable, as strings.
These strings will be used to build a dynamic regular expression so
they are very powerful. Some examples:
// disable these exact dates:
disabledDates: ["03/08/2003", "09/16/2003"]
// disable these days for every year:
disabledDates: ["03/08", "09/16"]
// only match the beginning (useful if you are using short years):
disabledDates: ["^03/08"]
// disable every day in March 2006:
disabledDates: ["03/../2006"]
// disable every day in every March:
disabledDates: ["^03"]
Note that the format of the dates included in the array should exactly
match the format config. In order to support regular expressions, if
you are using a date format that has "." in it, you will have to
escape the dot when restricting dates. For example: ["03\.08\.03"].
//Get the last date of the month. If in Feb 2012, lastDate is 29.
var lastDate = Ext.Date.getDaysInMonth(new Date());
//15th
var middleDate = 15;
//Construct regular expression
var disabledArray=[];
var today = Ext.Date.format(new Date(), 'm/d/Y');
var dateReg = /(\d{2}\/)\d{2}(\/\d{4})/;
disabledArray.push(today.replace(dateReg, '$1' + middleDate + '$2'));
disabledArray.push(today.replace(dateReg, '$1' + lastDate + '$2'));
//Something like "^(?!02/15/2012|02/29/2012).*$" including the two days allowed.
var disabledReg = '^(?!' + disabledArray.join('|') + ').*$';
//Apply the regular expression to date field
var dateField = new Ext.form.field.Date({
format: 'm/d/Y',
disabledDates: [disabledReg]
});
For some reason the date formatter using a pattern isn't working at all in my application. One thing that has crossed my mind is that it doesn't allow formatting for the x axis. Here's a snippet:
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date', 'YearMonth');
dataTable.addColumn('number', 'Beds');
dataTable.addColumn('number', 'Rooms');
var monthYearFormatter = new google.visualization.DateFormat({ pattern: "MMM yyyy" });
monthYearFormatter.format(dataTable, 0);
So elsewhere in a loop I do the following:
dataTable.addRow(d, currentRow.Beds, currentRow.Rooms]);
Where "d" is a valid date. It isn't formatted at all though, however when I do all of this, it just displays the default format.
Anyone done this before?
In order to format the values on the x-axis, you must use the format attribute in the options:
hAxis: { format: 'MMM yyyy' }
The line:
monthYearFormatter.format(dataTable, 0);
formats the values in the chart and must be written after the data inserting into the dataTable object.
#FrankyFred's answer works only for the labels over the axis and not the toolTip.
If you want to format the text on the toolTip so that what you have is right:
var monthYearFormatter = new google.visualization.DateFormat({
pattern: "MMM yyyy"
});
monthYearFormatter.format(dataTable, 0);