TranslationThTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\Jenssegers;
  12. class TranslationThTest extends TestCaseBase
  13. {
  14. public const LOCALE = 'th';
  15. public function testTimespanTranslated()
  16. {
  17. $date = new JenssegersDate(1403619368);
  18. $date = $date->sub('-100 days -3 hours -20 minutes');
  19. $this->assertSame('3 เดือน, 1 สัปดาห์, 1 วัน, 3 ชั่วโมง, 20 นาที', $date->timespan(1403619368));
  20. }
  21. public function testCreateFromFormat()
  22. {
  23. $date = JenssegersDate::createFromFormat('d F Y', '1 มกราคม 2015');
  24. $this->assertSame('2015-01-01', $date->format('Y-m-d'));
  25. $date = JenssegersDate::createFromFormat('D d F Y', 'เสาร์ 21 มีนาคม 2015');
  26. $this->assertSame('2015-03-21', $date->format('Y-m-d'));
  27. }
  28. public function testAgoTranslated()
  29. {
  30. $date = JenssegersDate::parse('-21 hours');
  31. $this->assertSame('21 ชั่วโมงที่แล้ว', $date->ago());
  32. $date = JenssegersDate::parse('-5 days');
  33. $this->assertSame('5 วันที่แล้ว', $date->ago());
  34. $date = JenssegersDate::parse('-3 weeks');
  35. $this->assertSame('3 สัปดาห์ที่แล้ว', $date->ago());
  36. $date = JenssegersDate::now()->subMonthsNoOverflow(6);
  37. $this->assertSame('6 เดือนที่แล้ว', $date->ago());
  38. $date = JenssegersDate::parse('-10 years');
  39. $this->assertSame('10 ปีที่แล้ว', $date->ago());
  40. }
  41. public function testFormatDeclensions()
  42. {
  43. $date = new JenssegersDate('10 march 2015');
  44. $this->assertSame('มีนาคม 2015', $date->format('F Y'));
  45. $date = new JenssegersDate('10 march 2015');
  46. $this->assertSame('10 มีนาคม 2015', $date->format('j F Y'));
  47. }
  48. public function testAfterTranslated()
  49. {
  50. $date = JenssegersDate::parse('+21 hours');
  51. $this->assertSame('อีก 21 ชั่วโมง', $date->ago());
  52. $date = JenssegersDate::parse('+5 days');
  53. $this->assertSame('อีก 5 วัน', $date->ago());
  54. $date = JenssegersDate::parse('+3 weeks');
  55. $this->assertSame('อีก 3 สัปดาห์', $date->ago());
  56. $date = JenssegersDate::parse('+6 months');
  57. $this->assertSame('อีก 6 เดือน', $date->ago());
  58. $date = JenssegersDate::parse('+10 years');
  59. $this->assertSame('อีก 10 ปี', $date->ago());
  60. }
  61. }