Doing this:
// JSON
{
"intlDateTime": "On the {{val, datetime}}",
}
i18next.t('intlDateTime', { val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)) });
// --> On the 12/20/2012
without interpolation escape to false
ends with a display of / instead of "/"
How can we use date format and avoid xss attacks at the same time ?
To solve the wrong display, I need to write:
{t('lastModified', {
val: new Date(Date.UTC(2012, 11, 20, 3, 0, 0)),
interpolation: { escapeValue: false },
})}
which I would like to avoid.
I'm super new to this and trying out Observable and Vega-Lite for the first time. The following code works when the datum is a quantitative string but not when it's a date.
vl.color({"condition":{"test":"datum['dateAnnounced']<'2020-03-15'","value":"black"}, "value":"red"})
Can someone show me the correct way to compare Date fields, please? Thanks in advance!
condition.test accepts Predictate. It has string format which you're using, but also it could be an object like this:
condition: {
test: {
field: 'dateAnnounced', // your date field
lt: { year: 2020, month: 3, date: 15 } // 'less than' a date in Vega DateTime format
}
}
They call this object "field predicate". It has field prop and a comparison operator lt or gt or equal, etc.
There are some examples from Field Predicate section of the doc:
{"field": "car_color", "equal": "red"} // car_color === red
{"field": "height", "lt": 180} // height < 180
{"field": "date", // 2006-01-01 < date && date < 2008-02-20
"range": [
{"year": 2006, "month": "jan", "date": 1},
{"year": 2008, "month": "feb", "date": 20}
]
}
I have this json that I want to convert to vb.net objects and I've tried to create classes for it without success. The json resonse looks like below:
{
"status": "success",
"result": {
"0": {
"id": 4991,
"sender_id": 2971,
"due_date": "0000-00-00 00:00:00",
"language_id": "sv",
"last_event": "2017-05-17 09:58:38",
"visible_name": "new offer",
"name": "new offer",
"reminder_date": "0000-00-00",
"offer_status": 0,
"offer_type": 1,
"user_details": "{\"first_name\":\"Beta\",\"last_name\":\"\",\"company\":\"Simplesign\",\"email\":\"beta#yopmail.com\",\"reg_no\":\"\",\"address\":\"\",\"telephone\":\"00923453596885\",\"post_code\":\"\",\"city\":\"\"}",
"unique_id": "591c02ae8c442",
"created_date": "2017-05-17 09:58:38",
"signed_date": "0000-00-00 00:00:00",
"last_sent_emailreminder": "0000-00-00 00:00:00",
"last_sent_smsreminder": "0000-00-00 00:00:00",
"unread_notification": 0,
"offer_rejected": 0,
"recieved_by": 0,
"pdf_url": "https://esign.simplesign.io/avtal/downloadpdf/4991/5b8648da173a5",
"details": [
{
"id": 5668,
"offer_sent_id": 4991,
"customer_id": 1556,
"offer_status": 1,
"sent_date": "2017-05-17 09:59:15",
"email_read_date": "0000-00-00 00:00:00",
"document_read_date": "0000-00-00 00:00:00",
"signed_date": "0000-00-00 00:00:00",
"reject_date": "0000-00-00 00:00:00",
"sender_ip": "103.75.244.108",
"read_ip": "",
"signed_ip": "",
"gps_location": "",
"first_name": "John",
"last_name": "Doe",
"company": "",
"is_sender": 0,
"extra_fields": "",
"user_details": "{\"id\":1556,\"full_name\":\"John\",\"email\":\"johndoe#yopmail.com\",\"company\":\"\",\"reg_no\":\"\",\"mobile\":\"\",\"address\":\"\",\"city\":\"\",\"zipcode\":\"\",\"country\":\"\",\"extra_fields\":\"\",\"invitation_order\":1,\"confirmation\":1,\"role\":1,\"id_attachment\":0,\"authentication\":1,\"paypal_amount\":0,\"invitation_type\":1}",
"request_attachment": "[]",
"pin_code": 0,
"invitation_order": 1,
"email": "johndoe#yopmail.com",
"unique_id": "591c02d30379f",
"signature": "",
"signature_type": "",
"signature_font": "",
"authentication_method": 1,
"role": 1,
"id_attachments": 0,
"paypal_amount": 0,
"offer_confirmation": 1,
"invitation_type": 1,
"attached_id": "",
"signature_image": "",
"recieved_by": 0,
"req_attached": "",
"is_pending": 0,
"schedule": "",
"schedule_userid": "",
"isretargeting": 1,
"signature_contrast": "",
"device_details": "",
"evidence_data": "",
"bankid_data": ""
}
],
"senderDetails": [
{
"id": 5667,
"offer_sent_id": 4991,
"customer_id": 0,
"offer_status": 4,
"sent_date": "2017-05-17 09:59:15",
"email_read_date": "0000-00-00 00:00:00",
"document_read_date": "0000-00-00 00:00:00",
"signed_date": "2017-05-17 09:59:15",
"reject_date": "0000-00-00 00:00:00",
"sender_ip": "103.75.244.108",
"read_ip": "",
"signed_ip": "103.75.244.108",
"gps_location": "",
"first_name": "Beta",
"last_name": "",
"company": "Simplesign",
"is_sender": 1,
"extra_fields": "",
"user_details": "{\"id\":2971,\"full_name\":\"Beta\",\"company\":\"Simplesign\",\"address\":\"\",\"country\":\"\",\"zipcode\":\"\",\"city\":\"\",\"reg_no\":\"\",\"email\":\"beta#yopmail.com\"}",
"request_attachment": "",
"pin_code": 0,
"invitation_order": 1,
"email": "beta#yopmail.com",
"unique_id": "591c02d3018d0",
"signature": "",
"signature_type": "",
"signature_font": "",
"authentication_method": 0,
"role": 0,
"id_attachments": 0,
"paypal_amount": 0,
"offer_confirmation": 0,
"invitation_type": 0,
"attached_id": "",
"signature_image": "",
"recieved_by": 0,
"req_attached": "",
"is_pending": 0,
"schedule": "",
"schedule_userid": "",
"isretargeting": 1,
"signature_contrast": "",
"device_details": "",
"evidence_data": "",
"bankid_data": ""
}
]
},
"userSetting": {
"userMsg": "",
"userSMS": "",
"userSubject": ""
},
"pagination": {
"totalRecords": 1,
"pagelimit": 10,
"currentpage": 0
}
},
"totaldata": {
"sent": 1,
"reviewed": 0,
"signed": 0,
"rejected": 0
}
}
The representation looks like this now:
Imports Microsoft.VisualBasic
Imports Newtonsoft.Json
Public Class RecipientDetail
<JsonProperty("id")>
Public Property id As Integer
<JsonProperty("customer_id")>
Public Property customer_id As Integer
<JsonProperty("sent_date")>
Public Property sent_date As String
<JsonProperty("document_read_date")>
Public Property document_read_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("first_name")>
Public Property first_name As String
<JsonProperty("company")>
Public Property company As String
<JsonProperty("is_sender")>
Public Property is_sender As String
<JsonProperty("extra_fields")>
Public Property extra_fields As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("invitation_order")>
Public Property invitation_order As Integer
<JsonProperty("email")>
Public Property email As String
<JsonProperty("offer_confirmation")>
Public Property offer_confirmation As String
<JsonProperty("invitation_type")>
Public Property invitation_type As String
End Class
Public Class SenderDetail
<JsonProperty("id")>
Public Property id As Integer
<JsonProperty("customer_id")>
Public Property customer_id As Integer
<JsonProperty("sent_date")>
Public Property sent_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("first_name")>
Public Property first_name As String
<JsonProperty("company")>
Public Property company As String
<JsonProperty("is_sender")>
Public Property is_sender As String
<JsonProperty("extra_fields")>
Public Property extra_fields As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("email")>
Public Property email As String
End Class
Public Class ContractDetail
<JsonProperty("sender_id")>
Public Property sender_id As Integer
<JsonProperty("last_event")>
Public Property last_event As String
<JsonProperty("visible_name")>
Public Property visible_name As String
<JsonProperty("offer_status")>
Public Property offer_status As String
<JsonProperty("user_details")>
Public Property user_details As String
<JsonProperty("created_date")>
Public Property created_date As String
<JsonProperty("signed_date")>
Public Property signed_date As String
<JsonProperty("offer_rejected")>
Public Property offer_rejected As String
<JsonProperty("name")>
Public Property name As String
<JsonProperty("contract_id")>
Public Property contract_id As Integer
<JsonProperty("recipientDetails")>
Public Property recipientDetails As IList(Of RecipientDetail)
<JsonProperty("pdf_url")>
Public Property pdf_url As String
<JsonProperty("senderDetails")>
Public Property senderDetails As IList(Of SenderDetail)
End Class
Public Class Pagination
<JsonProperty("totalRecords")>
Public Property totalRecords As Integer
<JsonProperty("pagelimit")>
Public Property pagelimit As Integer
<JsonProperty("currentpage")>
Public Property currentpage As Integer
End Class
Public Class Result
Public Property ContractDetail As IList(Of ContractDetail)
End Class
Public Class SS_History
<JsonProperty("status")>
Public Property status As String
<JsonProperty("result")>
Public Property result As Result
End Class
The problem is that the result is empty, so for some reason it seems that I've done the result class wrong.
If someone have a suggestion of how to solve it I would be most grateful.
Peter
At first, copy the json string.
Open VS, add a new empty class.
Select Edit on VS menu, then Paste Special and Paste Json as Classes. Class will be generated automaticaly.
The first object will be the RootObject, on that one, add Newtonsoft's decorator.
After you added all decorators, you as well can change property names or object names.
Imports Newtonsoft.Json
Public Class Rootobject
<JsonProperty("status")>
Public Property status As String
<JsonProperty("result")>
Public Property result As Result
<JsonProperty("totaldata")>
Public Property totaldata As Totaldata
End Class
etc..
Deserialize it this way:
Json
I have the following data for a timezone:
{
"Id": "Pacific Standard Time",
"DisplayName": "(UTC-08:00) Pacific Time (US & Canada)",
"StandardName": "Pacific Standard Time",
"DaylightName": "Pacific Daylight Time",
"BaseUtcOffset": "-08:00:00",
"AdjustmentRules": [{
"DateStart": "0001-01-01T00:00:00Z",
"DateEnd": "2006-12-31T00:00:00Z",
"DaylightDelta": "01:00:00",
"DaylightTransitionStart": {
"TimeOfDay": "0001-01-01T02:00:00Z",
"Month": 4,
"Week": 1,
"Day": 1,
"DayOfWeek": 0,
"IsFixedDateRule": false
},
"DaylightTransitionEnd": {
"TimeOfDay": "0001-01-01T02:00:00Z",
"Month": 10,
"Week": 5,
"Day": 1,
"DayOfWeek": 0,
"IsFixedDateRule": false
},
"BaseUtcOffsetDelta": "00:00:00"
}, {
"DateStart": "2007-01-01T00:00:00Z",
"DateEnd": "9999-12-31T00:00:00Z",
"DaylightDelta": "01:00:00",
"DaylightTransitionStart": {
"TimeOfDay": "0001-01-01T02:00:00Z",
"Month": 3,
"Week": 2,
"Day": 1,
"DayOfWeek": 0,
"IsFixedDateRule": false
},
"DaylightTransitionEnd": {
"TimeOfDay": "0001-01-01T02:00:00Z",
"Month": 11,
"Week": 1,
"Day": 1,
"DayOfWeek": 0,
"IsFixedDateRule": false
},
"BaseUtcOffsetDelta": "00:00:00"
}],
"SupportsDaylightSavingTime": true
}
and the following date:
2019-01-05T07:30:07Z
Using moment, i'd like to convert this to my current locale which is
en-GB
How do i go about doing this with momentjs?
the problem seems to be that the date format i have is not compatible with moment.
I've prepared a jsfiddle with variables that i have access to:
http://jsfiddle.net/jimmyt1988/xe7ha5ms/1/
Your input is in ISO 8601 format recognized by moment. You can parse it using moment.tz:
The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier.
then you can convert it to desired timezone using tz():
The moment#tz mutator will change the time zone and update the offset.
You can set locale on a moment object using locale() and then use format() to display value.
Here a code sample:
console.log(
moment.tz('2019-01-05T07:30:07', 'America/Los_Angeles') // parse input in given tz
.tz('Europe/London') // Convert moment to desired zone
.locale('en-gb') // set en-gb locale
.format('LLLL') // display result
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
Figured it out, by using the utcOffset method:
http://jsfiddle.net/jimmyt1988/xe7ha5ms/2/
moment("2019-01-05T07:30:07Z")
.utcOffset("-08:00:00")
.format("DD/MM/YYYY HH:mm:ss");
I'm using VB in ASP.NET and I've been looking at trying to serialize the below JSON from a WebService(webmethod). plz help the exact properties that i used.
{
"api_version" : 4 ,
"hotel_ids" : [97497],
"start_date" : "2013-07-01",
"end_date" : "2013-07-03",
"num_adults" : 2,
"num_rooms" : 1,
"currency" : "USD",
"user_country" : "US",
"device_type" : "d",
"query_key" : "6167a22d1f87d2028bf60a8e5e27afa7_191_1360299600000_2_2",
"lang" : "en_US",
"num_hotels" : 1,
"hotels" :
[
{
"hotel_id": 97497,
"room_types":
{
"Fenway Room":
{
"url": "http: //www.partner-site.com/hotel_commonwealth/fenway_room?start_date=2013-07-01&end_date=2013-07-05&num_adults=2",
"price": 178.50,
"fees": 80,
"fees_at_checkout": 0,
"taxes": 20,
"taxes_at_checkout": 0,
"final_price": 278.50,
"discounts":
[
{
"marketing_text": "10% off entire stay during July",
"is_percent": true,
"amount": 10,
"price": 20,
"fees": 0,
"fees_at_checkout": 0,
"taxes": 0,
"taxes_at_checkout": 0,
"final_price": 20
},
{
"marketing_text": "1% off web special",
"is_percent": true,
"amount": 1,
"price": 2,
"fees": 0,
"fees_at_checkout": 0,
"taxes": 0,
"taxes_at_checkout": 0,
"final_price": 2
},
{
"marketing_text": "Waive property fee",
"is_percent": false,
"amount": 25,
"price": 0,
"fees": 25,
"fees_at_checkout": 0,
"taxes": 0,
"taxes_at_checkout": 0,
"final_price": 25
}
],
"currency": "USD",
"num_rooms": 1,
"room_code": "SINGLE",
"room_amenities":
[
"BREAKFAST_AND_LUNCH_INCLUDED",
"ROOM_WITH_A_VIEW"
]
}
}
}
]
}
Use Code like this:
This is my entity class
Public Class Book
' autocomplete example needs "id", "value" and the "label" variables to be sent back.
' do not change or remove "id", "value" and the "label" variables
Public Property id() As String
Public Property label() As String
Public Property value() As String
Public Property Author() As String
Public Property Genre() As String
Public Property Price() As String
Public Property Publish_date() As String
Public Property Description() As String
End Class
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' Query string 'term' is for autocomplete. By default, it sends the variable
' "term" with the search word to the backend page.
Dim searchText As String = context.Request.QueryString("term")
Dim books As Collection = New Collection
Dim ds As New DataSet()
ds.ReadXml(HttpContext.Current.Server.MapPath("jsonfile"))
Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = [String].Format("title like '{0}*'", searchText.Replace("'", "''"))
Dim book As Book
For Each myDataRow As DataRowView In dv
book = New Book()
book.id = myDataRow("id").ToString()
book.value = myDataRow("title").ToString()
book.label = myDataRow("title").ToString()
book.Author = myDataRow("author").ToString()
book.Genre = myDataRow("genre").ToString()
book.Price = myDataRow("price").ToString()
book.Publish_date = myDataRow("publish_date").ToString()
book.Description = myDataRow("description").ToString()
books.Add(book)
Next
Dim serializer As JavaScriptSerializer = New JavaScriptSerializer
Dim jsonString As String = serializer.Serialize(books)
context.Response.Write(jsonString)
End Sub