क्या किसी को टाइमस्टैम्प में समय के अंग्रेजी प्रस्तुतियों को बदलने के लिए किसी भी अच्छी कक्षा/पुस्तकालय के बारे में पता है?अंग्रेजी से समय
लक्ष्य "दस साल से अब" और "तीन सप्ताह" और "10 मिनट में" प्राकृतिक भाषा वाक्यांशों को परिवर्तित करना है और उनके लिए एक सर्वश्रेष्ठ मैच यूनिक्स टाइमस्टैम्प का काम करना है।
मैंने इसे पाने के लिए कुछ सुंदर और अवांछित कोड को हैक किया है, लेकिन मुझे यकीन है कि कैलेंडर और ऐसे के लिए वहां बहुत अच्छे पार्सर्स हैं।
private function timeparse($timestring)
{
$candidate = @strtotime($timestring);
if ($candidate > time()) return $candidate; // Let php have a bash at it
//$thisyear = date("Y");
if (strpos($timestring, "min") !== false) // Context is minutes
{
$nummins = preg_replace("/\D/", "", $timestring);
$candidate = @strtotime("now +$nummins minutes");
return $candidate;
}
if (strpos($timestring, "hou") !== false) // Context is hours
{
$numhours = preg_replace("/\D/", "", $timestring);
$candidate = @strtotime("now +$numhours hours");
return $candidate;
}
if (strpos($timestring, "day") !== false) // Context is days
{
$numdays = preg_replace("/\D/", "", $timestring);
$candidate = @strtotime("now +$numdays days");
return $candidate;
}
if (strpos($timestring, "year") !== false) // Context is years (2 years)
{
$numyears = preg_replace("/\D/", "", $timestring);
$candidate = @strtotime("now +$numyears years");
return $candidate;
}
if (strlen($timestring) < 5) // 10th || 2nd (or probably a number)
{
$day = preg_replace("/\D/", "", $timestring);
if ($day > 0)
{
$month = date("m");
$year = date("y");
return strtotime("$month/$day/$year");
}
else
{
return false;
}
}
return false; // No can do.
}
कैसे के बारे में "तीन साल, दो दिन और पांच मिनट भविष्य में "इनपुट के रूप में? – chelmertz
हां, बिल्कुल इसी तरह की चीजें। मुझे इसकी ही आवश्यकता थी। –
"तीन साल, दो दिन और पांच मिनट" और इसी तरह एक आईएस 868601 अंतराल में आसानी से अनुवाद करना चाहिए: "पी 3 वाई 2 डीटी 5 एम" जिसे आप डेटइंटरवाल में फ़ीड कर सकते हैं और डेटटाइम ऑब्जेक्ट में जोड़ सकते हैं। – dnagirl