Can't Format Date in GraphQL in Gatsby Site - firebase

I am having trouble formatting a date in Gatsby. I have sourced some data from firestore. One of the fields that I have sourced is called datePublished and it contains a number in the form of a timestamp (e.g., 1576945502000). Indeed, it really is a timestamp, but it got saved to firestore in the number format type.
Now, I would like to format the datePublished field using the formatString function in graphql -- as noted here: https://www.gatsbyjs.org/docs/graphql-reference/#dates
But I can't get the formatting to work. Whether I try to format the string in graphiql or on my site, it does not work. Here is the code that I tried:
query MyQuery {
allNewsFeed {
edges {
node {
published(formatString:"dddd Mo, YYYY")
}
}
}
}
And this is the error message that I get in graphiql:
Unknown argument "formatString on field 'datePublished' of type 'NewsFeed'.
If I dig a little deeper, I notice that the field type in firestore is listed as number and in the graphiql document explorer it is listed as a FloatQueryOperatorInput.
What's more, I did a little experiment where I tried to save the same number as a string, number and timestamp in firestore. Neither the string or number format worked and for whatever reason, the gatsby-firesource plugin will not pull in the field with a timestamp format.
So I am wondering, what do I have to do to get this to work in gatsby?
Any ideas?
Thanks.

I had a similar situation with Gatsby not accepting "formatString" on a date field, for me what solved the issue was to change the format of the field to YYYY-MM-DD so it went from 02 06 2017 to 2017-06-02 and gatsby got the hint that that field represents a date.
It seems gatsby "reads" the data and guesses the type and based on that we get certain functionality.
Since gatsby uses moment.js I'm guessing the YYYY-MM-DD format is picked up by it.
I'm using MDX so it was really easy for me to change the format of my date field since it's just plain text, I'm not sure you have the same luxury with firestore but I hope this at least give you some ideas to try out. Good luck!

Related

SugarCRM Get an effective TimeDate from a SugarBean field

I must be missing something obvious, but it seems that I'm unable to find a way to get the TimeDate object from the value of a SugarBean field.
Let's say I get a specific Lead with this kind of call:
$lead = BeanFactory::retrieveBean('Leads', "18bfc69e-8cd4-11e7-ad08-000c29b1a36e");
then any call to this:
$lead->date_entered
will return a string value: "2017-08-29 16:05" (note the absence of seconds).
So then, for example, if I try to use such value to create a SugarTimeDate:
$TimeDate = new TimeDate();
$SugarTimeDate = $TimeDate->fromDb($lead->date_entered);
it will return false, since the value provided to fromDb() is not in the proper format (the seconds are missing).
When looking at the SQL table with Toad, I can see that the information is effectively stored in the database as a DateTime, with the value 08/29/2017 16:05:56. But the SugarBean object provides it as a text with a format that is incomplete.
So how can you get the effective SugarTimeDate, TimeDate or DateTime from a Field in a given SugarBean, ideally as an object?
I searched, and all the example I found was about creating a new date object from Now to set to a field in a SugarBean, but none to set a datetime field from an existing datetime field.
Any hint would be highly appreciated.
By playing around, and with some help from Patrick McQueen, it appears there 2 ways to get the effective date value of a field.
First solution I found was to do a SugarQuery with a select on the needed fields, which then returns the full date information, so "2017-08-29 16:05:56". A bit overkill, but it does the job.
The other solution brought up by Patrick is to use the fetcher_row array from the bean object, which will return the full date information also. So:
$lead->fetched_row['date_entered']
will returns also "2017-08-29 16:05:56".
So in any case an effective date is required ("round-trip" with a get then a set, or some sync requirement), the fetched_row[] is the solution, and the "direct" call to the field $bean->field is to be definitely avoided.
I wasn't 100% clear what you were trying to accomplish (see my comments), but I'm guessing that you want the fromUser() function instead, i.e.
$SugarTimeDate = $TimeDate->fromUser($lead->date_entered);
The reason why, is that Sugar prepares the data for the GUI (including formatting the date as per user preferences) at the point your code is being called. This includes stripping out the seconds. Doing the above fromUser() function will return a SugarDateTime object based on the current user's configured date format with a full date string as a "date" property. This, in turn, could be dealt with elsewhere by using this standard format.

Kibana shorten column name in data table

Is it possible to beautify this data table using advanced JSON or something?
Currently, I'm getting this back:
Ideally, I'd like to get rid of everything else, except date, which is yyyy-MM-dd.
I've added this JSON to Advanced JSON Input:
{
"format" : "yyyy-MM-dd"
}
It does work in backend side, results are brought back in this format. However - Kibana still displays them in its own manner.
Elasticsearch version - 2.0
Kibana version - 4.2
you can change the data format with kibana in the menu of the index. You go to the camp and select type date and the format. They allow multiple diferents format. As yyyy-mmmm that even display the name of the month.
EDIT:
The best option to dont change all the date is perhaps duplicate the date and only change the new data with the new format.
PD: is awesome that with scripted field you can do doc['time].value and you can not change the type of the new field but Kibana change the value to miliseconds.

SOLR Date range

I have to make an ezfind search page with date functions. For the SOLR filter I tried to use something like this: attr_publish_date_dt:[NOW-6MONTH TO NOW] but I don't get any result.
If I use it this way attr_publish_date_dt:[* TO NOW], it works. But all queries without an asterisk on the left hand don't work.
attr_publish_date_dt contains a unix timestamp so I also tried to use 2 timestamps from the attr_publish_date_dt:[* TO NOW] result, instead of [NOW-6MONTH TO NOW], but then I get also no results.
Can anyone help me please? Thanks in advance
Frank
Date searches are supported on a date field. You will need to define a field of that type, and submit dates in ISO-8601 format.
http://lucene.apache.org/solr/4_4_0/solr-core/org/apache/solr/schema/DateField.html
If you cannot properly format the timestamp before sending it to Solr, you may be able to use a DateFormatTransformer or a ScriptTransformer to do the job.
http://wiki.apache.org/solr/DataImportHandler#DateFormatTransformer
http://wiki.apache.org/solr/DataImportHandler#ScriptTransformer

Reporting Services: DateTime parameter not showing the time part when its midnight

I need to add a 'StartDate' parameter to a report in Reporting Services 2005, which should represent the current date, at midnight.
If I use Now() as expression, it will correctly use midnight in the calculations, but to the user, the time part will not be shown.
13/12/2011
which can be confusing because then the user doesn't really realise he or she can type in a time part.
How can I format this date to the following:
13/12/2011 00:00
while keeping the parameter as a DateTime datatype.?
Edit: I've checked the duplicate question and tried to apply it to my case, but run into the following phenomenom:
If I try:
=DateTime.Parse(Format(Now().Date().AddSeconds(1), "dd/MM/yyyy HH:mm:ss"))
Then the parameter shows "14/12/2011 00:00:01" which is confusing for the users, so I then tried the following:
=DateTime.Parse(Format(Now().Date().AddSeconds(1), "d/M/yyyy HH:mm"))
But then the parameter shows "14/12/2011" again! In other words, the time part is gone again!
Who invented this stuff? :P
Your formula with .Parse(Format(... causes redundant work that is messing things up. Try this:
=Now().Date().AddSeconds(.001)
Use Format. For example: Format(Parameters!SelectedDate.Value, "d/M/yyyy HH:mm")
Here is a list of DateTime identifiers for use with Format.
Edit:
I get it now, you want 00:00 to show up in the parameter input calendar in the report viewer. The time part won't show up when it's set to midnight. This is by design. If you're using 2005 or earlier, Jamie's solution won't work and you're stuck.

WordPress custom content type date field

Hey, I'm trying to build the most intuitive possible Event post type. I'm wondering if there's a core method to both print out and capture the contents of a date field - specifically year/month/day, I don't need hours/minutes. I also need to be able to sort entries by date to print out later - for instance, I need all of the events from January. Something that can save me formatting the fields, and then parsing and saving them manually.
Any ideas are welcomed! Thanks in advance for your time.
There was no rock solid WP core solution to this, but the system I created is composed of:
SQL CONCAT to compare a date field to CURDATE, etc.
PHP strToTime to get the date back from the database
Generally speaking, if you save your date to the DB in UNIX time format it's easy to work with in SQL queries and in your PHP output.

Resources