How to get Order Time in Magento? - date

I am trying to rewrite my PDF invoices in Magento. How can i display the created time without the date of a Order?
I am preparing the class insertOrder() in /app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php.
$page->drawText(Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'short', false), 100, 100, 'UTF-8');
shows only the time in combination with date.

One way to display the time part only would be this:
$sTime = Mage::app()
->getLocale()
->date(strtotime($order->getCreatedAtStoreDate()), null, null, false)
->toString('H:m:s');
$page->drawText($sTime, 100, 100, 'UTF-8');
Magento's locale uses a modified Zend_Date class for date/time operations.
See the toString() method of app/code/core/Zend/Date.php for parameter infos.

Related

Formik Yup date validation - accept European DD/MM/YYYY format

I am trying to use Yup with Formik for my user profile screen. The validation works fine but it expects the format of the date entered by the user to be in USA format MM/DD/YYYY rather than the application required European/UK standard format DD/MM/YYYY. Entering 31/12/1995 fails validation.
dateOfBirth: Yup.date()
.required("Date of Birth is required")
.max(dateToday, "Future date not allowed")
I have searched through the Yup docs and SO but I can't work out how to do this. Any ideas?
You can use the transform method to parse value.
Like:
startDate: Yup.date()
.transform(value => {
return value ? moment(value).toDate() : value;
})
.required("Date of Birth is required")
.max(dateToday, "Future date not allowed");
I had this same issue myself and resolved it using the example in the Yup README replacing MomentJS with date-fns which is what I use for date manipulation.
Value returns Invalid Date before you custom transform is applied so you must use the original value and context to check to see if you need to run the transform logic at all and if so run it on the value from the field and not the transformed value.
Yup transform docs and date example
import { parse } from 'date-fns';
[...]
date()
.transform((value, originalValue, context) => {
// check to see if the previous transform already parsed the date
if (context.isType(value)) return value;
// Date parsing failed in previous transform
// Parse the date as a euro formatted date string or returns Invalid Date
return parse(originalValue, 'dd/MM/yyyy', new Date());
})
This works perfectly for me and works for both US and UK date formats (you will still need to perform manipulation on the date if its in the us format as it will submit this value as valid)
If you ONLY want UK/Euro dates then just remove the context type check
.transform((value, originalValue) => parse(originalValue, 'dd/MM/yyyy', new Date()))

How to assign current date to a date field in odoo 10

How to show current date before clicking the date field in odoo?
Odoo Date field class provides methods to get default values for like today.
For dates the method is called context_today() and for datetimes context_timestamp(). You are able to pass a timestamp to this methods to either get today/now (without timestamp) or a timestamp which will be formed by the logged in users timezone.
Code Example:
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
def _default_my_date(self):
return fields.Date.context_today(self)
my_date = fields.Date(string='My Date', default=_default_my_date)
Or the lambda version:
my_date = fields.Date(
string='My Date', default=lambda s: fields.Date.context_today(s))
I found it.It is Simple, just write this on your python code like:
date = fields.Datetime(string="Date", default=lambda *a: datetime.now(),required=True)
or
like this
date = fields.Datetime(string="Date current action", default=lambda *a: datetime.now())
or
like this
date = fields.Date(default=fields.Date.today)

Change date storage format in MongoDB

In an input json file i receive dates in this format:
{ "dt_received" : "2016-01-22T12:35:52.123+05" }
When loaded into MongoDB, those dates are stored this way:
dt_received: "2016-01-22T07:35:52.123Z"
The issue is that i need the timezone to calculate my indicator.
In constraint, i can't create new columns such as "dt_received_timezone".
So i'm looking for changing the date storage format into MongoDB in order to make the timezone appear (or at least not disapear)
Is it a way to to this? Or any solution ?
If you receive data from various time zones and want to keep the time zone offset, you will have to save it into the database like this:
var now = new Date();
db.data.save( { date: now, offset: now.getTimezoneOffset() } );
You can then reconstruct the original time like this
var record = db.data.findOne();
var localNow = new Date( record.date.getTime() - ( record.offset * 60000 ) );
See the documentation for further details

How to use nest in d3 to group using the 'month' as key, but my csv file contains the whole date?

var data = d3.nest()
.key(function(d) { return d.date;})
.rollup(function(d) {
return d3.sum(d, function(g) {return g.something; });
}).entries(csv_data);
using this code above I can group by date which is in the format yyyy-mm-dd , but I want to group using the month as key. How do I do this ?
You can use the builtin method d3.timeMonth() to get the first day of the month for a date like:
d3.nest()
.key(function(d){ return d3.timeMonth(d.date); });
If d.date is not already a javascript Date object you have to first parse it to be one.
var date_format = d3.timeFormat("%Y-%m-%d");
csv_data.forEach(function(d, i) {
d.date = date_format.parse(d.date);
};
You need to change the key function to return the value you want to nest by. In most cases, the key function just returns a property of the data object (like d.date), but in your case the function will require a little more calculation.
If your date is stored as a string of the format "yyyy-mm-dd" you have two options for extracting the month: either
use regular expressions to extract the portion of the string in between the "-" characters, or
convert it to a date object and use date methods to extract a component of the date.
Browsers differ in which date formats they can convert using the native Javascript new Date(string) constructor, so if you're using date objects you may want to use a d3 date format function's format.parse(string) method to be sure of consistent results.

In yii how to find date is greater than current date

I am working in Yii framework. I am having Poll table with fields as-
-pollId
-pollQuestion
-Isactive
-publishDate
-isPublish
when new poll is created,that date get inserted into publishDate field.
e.g.2012-04-04 02:23:45 In this format entry get inserted.
Now i want to check weather this publishDate is smaller than today's date or current date. i.e.publishDate should not be greater than current date.
So how to check this in yii? Please help me
As per normal PHP. Assuming $model is the submitted form and you have assigned (after the form has been submitted) $model->attributes = $_POST['MyModel']
You can then use:
if ($model->publishDate < date('Y-m-d H:i:s')){
// it is smaller
}
Another thing you could look at is using Yii's model validation. You could store the created date (which would be todays date) and then compare that to the publishDate in the form submit:
$model->created = date("Y-m-d H:i:s");
if ($model->validate){
...
}
And in your Poll model:
array('publishDate ','compare','created','operator'=>'<', 'message'=>'Publish Date must be smaller than the current date'),