”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 时间数据系列:故事的其余部分

时间数据系列:故事的其余部分

发布于2024-11-09
浏览:852

Time Data Series: The Rest of the Story

Time Data Series: The Rest of the Story - AdatoSystems

It’s been a while since I wrote about PHP Zmanim – the work I’ve done with it and the things I’ve learned while implementing it. But despite the delay, I always intended to continue the conversation. That’s what we’re doing today 

In my first post I explained how to install and get started with the PHP Zmanim library. Then in the next post I dug into calculating more complex times, and the real power of the tool – applying the most common Rabbinic opinions for various zmanim. I’m picking up where I left off with minimal overlap, so if you need to take a minute to get back up to speed,  I’ve linked to those previous posts.

The goal today is to explore uses of PHP Zmanim that move beyond the relatively straightforward use of the library. That includes:

  • Taking a standard time and adjusting it for synagogue specific use cases (“Mincha starts 25 minutes before Shkia each day”).
  • Using PHP Zmanim library functions and methods that provide non-time calculations – such as the weekly Torah Portion, the Hebrew date, and whether a specified date is a holiday (like Rosh Chodesh or Sukkot).

Acknowledgements

Once again need to begin by stating my gratitude to the folks who made all of this possible. Foremost among a long list of names is Zachary Weixelbaum, the maintainer of the PHP Zmanim library itself; and Eliyahu Hershfeld: creator of the Kosher Java library upon which PHP Zmanim is based.

A quick refresher

When we left off, we had a solid basic php script that:

  • sets variables for the location (in latitude/longitude), along with the time zone and elevation.
  • Sets the date
  • creates a php zmanim object from those variables
  • uses the built-in methods to calculate the time for anything from sunrise to mincha to tzeit hakochavim

It looked like this:

sunrise;
echo "$sunrise\n";
?>

But sunrise is just the beginning. Using any of the built-in calculations (which are described on the github readme page), you can pull a wide variety of times. For example, to get Mincha Gedola using a specific Rabbinic opinion, I could include:

$gedolah = $zmanim->minchaGedola16Point1Degrees

In the last blog I also covered ways to use PHP Zmanim’s format method to make the output more readable:

$gedolah = $gedolah->format('g:i a');

“Salt to taste” – adjusting times

For those who don’t spend a lot of time in synagogue (no blame, no shame, you’re still welcome here) it may not be obvious, but – despite the name of the zman – very few organizations pray Mincha (afternoon prayers) at Mincha Ketana, Mincha Gedola, or Plag haMincha.

In fact, a lot of the work with regard to calculating times has less to do with the straight “what time is Mincha Gedola?” and more with “how late in the day can we reasonably schedule Mincha so that everyone has time to get here after work; but not SO late that nobody comes because they’ll miss dinner?”

If that’s too theoretical, allow me to share the logical jenga puzzle my synagogue considers when setting up the weekly schedule:

  • Friday night candle lighting: Shkia (sunset) minus 18 minutes
  • Summer Friday Mincha: Plag haMincha (using “plagHaminchaAteretTorah”) minus 20 minutes
  • Winter Friday Mincha: Shkia (sunset) minus 22 minutes
  • Saturday Mincha: Shkia minus 40 minutes
  • Saturday Ma’ariv: Shkia plus 50 minutes
  • Saturday end of Shabbat: Shkia plus 45 minutes
  • Weekday Mincha: find the earliest shkia for the week, then subtract 17 minutes

While all the other times I covered in earlier blogs still matter, hopefully you are starting to realize that they matter less often than one might expect.

So how DO you take a time (like shkia/sunset) and then add or subtract minutes? We’ll start off with the same script we had before:

To that we’ll add the code to get sunset:

$sunset = $zmanim->sunset;

and then we’ll subtract 18 minutes to get candle lighting time:

$candles = date('g:i a', strtotime($sunset . " -18 minutes"));

That’s right. You just use php’s own string to time function. I’m sorry if I kept you in suspense. But it’s really just that easy.

What’s the Torah portion? What’s the Hebrew date? When is Rosh Chodesh?

(…and other essential but vexing questions often asked in and around your synagogue.)

Along with date calculations, the KosherJava library (and therefore the PHP Zmanim library) have methods and functions to quickly provide information like the ones asked above.

The first thing to understand is that the PHP Zmanim object we’ve been working with so far has been a Zmanim object – an object that has a set of specific times for a particular date. For things involving the dates themselves, we instantiate a  jewishCalendar object. The good news is that it’s MUCH easier to create. All you need is the year, month, and day.

We now have a jewishCalendar object to work with and can use methods similar to the ones we found for times. For example: Presuming the date we selected was a Saturday, we can get the Torah portion:

$format = Zmanim::format();
$parshaeng = json_decode('"' . $format->formatParsha($jewishCalendar) . '"');

(ignore the $format setting for now. We’ll dig into it in just a bit).

If you ran that code, $parshaeng would give you:

Parshas Ki Savo

You’ll notice we didn’t need to provide latitude, longitude, time zone, etc. I cannot stress enough that this capability alone – the ability to get dates, Torah portions, and more – makes the PHP Zmanim library useful all on its own, even without the time calculations. 

Can I get that in Hebrew?

The Torah Portion? Of course! This is where the $format line comes in. 

First, an explanation of what it is: It’s a method that modifies objects like Zmanim and jewishCalendar, setting the display and output options.  Setting Zmanim::format() without any other information defaults to English. But then you can tell the system you want Hebrew with this additional line:

$format->setHebrewFormat(true)

Now if you run the same json_decode(‘”‘ . $format->formatParsha($jewishCalendar) . ‘”‘) line, you’d get:

כי תבוא

Putting it all together:

formatParsha($jewishCalendar) . '"');
$format->setHebrewFormat(true);
$parshaheb = json_decode('"' . $format->formatParsha($jewishCalendar) . '"');
echo "$parshaheb - $parshaeng\n";

This would display: כי תבוא – Ki Savo

What day is it?

More specifically, what HEBREW day is it?

Like the previous example, we start out with a jewishCalendar and a format object

$jewishCalendar = Zmanim::jewishCalendar(Carbon::createFromDate($theyear, $themonth, $theday));
$format = Zmanim::format();

Then we add the same line to set the format to Hebrew.

$format->setHebrewFormat(true);

And finally (and fairly simply) we ask for a straight calendar object output:

$zmandate = json_decode('"' . $format->format($jewishCalendar) . '"');

That’s literally all you need. The result is something like this:

17 Elul, 5784

Yes, even though we specified setHebrewFormat it came out in English.

Can I get that in ACTUAL Hebrew?

In order to get the Hebrew date to show up fully in Hebrew – both words and letters – we invoke a slightly different method called, appropriately enough, HebrewDateFormatter. Presuming (once again) you set up your initial variables and created a jewishCalendar object, the code to output a Hebrew language date would be:

$hebformat = HebrewDateFormatter::create();
$hebformat->setHebrewFormat(true);
$hebdate = json_decode('"' . $hebformat->format($jewishCalendar) . '"');
print("Hebrew date: $hebdate\n");

which would give you:

Hebrew date: י״ח אלול תשפ״ד

Is today the day?

Sometimes you need to check if a specific date is… well, a specific day. Like Rosh Chodesh (the new month) or part of a multi-day holiday (like Sukkot).

It turns out that PHP Zmanim method makes this very simple. Presuming you’ve started off in the same way as the other examples,

Once you’ve set up the jewishCalendar object it’s as simple as

$jewishCalendar->isRoshHashana();
$jewishCalendar->isSuccos(); 

If the date matches the holiday, it will return “true” and you can proceed with whatever logic or process you want, such as displaying the date (or not).

So what’s next?

Believe it or not, there’s still more to cover. In the coming weeks whenever I get to it, I’d like to cover ways to leverage the built-in astronomy functions for time calculations. Believe it or not, it can really matter in terms of having truly accurate times for things like the start and end of Shabbat and holidays, along with other observances.

In the meanwhile, if there’s something else you’d like to see me cover; or if you have questions, corrections, or kudos, feel free to leave them in the comments below.

版本声明 本文转载于:https://dev.to/adatole/time-data-series-the-rest-of-the-story-555h?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • 如何修复 macOS 上 Django 中的“配置不正确:加载 MySQLdb 模块时出错”?
    如何修复 macOS 上 Django 中的“配置不正确:加载 MySQLdb 模块时出错”?
    MySQL配置不正确:相对路径的问题在Django中运行python manage.py runserver时,可能会遇到以下错误:ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-...
    编程 发布于2024-11-13
  • Bootstrap 4 Beta 中的列偏移发生了什么?
    Bootstrap 4 Beta 中的列偏移发生了什么?
    Bootstrap 4 Beta:列偏移的删除和恢复Bootstrap 4 在其 Beta 1 版本中引入了重大更改柱子偏移了。然而,随着 Beta 2 的后续发布,这些变化已经逆转。从 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    编程 发布于2024-11-13
  • 大批
    大批
    方法是可以在对象上调用的 fns 数组是对象,因此它们在 JS 中也有方法。 slice(begin):将数组的一部分提取到新数组中,而不改变原始数组。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index p...
    编程 发布于2024-11-13
  • 如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    如何在 PHP 中组合两个关联数组,同时保留唯一 ID 并处理重复名称?
    在 PHP 中组合关联数组在 PHP 中,将两个关联数组组合成一个数组是一项常见任务。考虑以下请求:问题描述:提供的代码定义了两个关联数组,$array1 和 $array2。目标是创建一个新数组 $array3,它合并两个数组中的所有键值对。 此外,提供的数组具有唯一的 ID,而名称可能重合。要求...
    编程 发布于2024-11-13
  • 在 Go 中使用 WebSocket 进行实时通信
    在 Go 中使用 WebSocket 进行实时通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    编程 发布于2024-11-13
  • 除了“if”语句之外:还有哪些地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    除了“if”语句之外:还有哪些地方可以在不进行强制转换的情况下使用具有显式“bool”转换的类型?
    无需强制转换即可上下文转换为 bool您的类定义了对 bool 的显式转换,使您能够在条件语句中直接使用其实例“t”。然而,这种显式转换提出了一个问题:“t”在哪里可以在不进行强制转换的情况下用作 bool?上下文转换场景C 标准指定了四种值可以根据上下文转换为 bool 的主要场景:语句:if、w...
    编程 发布于2024-11-13
  • 如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 查找今天生日的用户?
    如何使用 MySQL 识别今天生日的用户使用 MySQL 确定今天是否是用户的生日涉及查找生日匹配的所有行今天的日期。这可以通过一个简单的 MySQL 查询来实现,该查询将存储为 UNIX 时间戳的生日与今天的日期进行比较。以下 SQL 查询将获取今天有生日的所有用户: FROM USERS ...
    编程 发布于2024-11-13
  • 使用 html css 和 javascript 的图像滑块 carosual https://www.instagram.com/webstreet_code/
    使用 html css 和 javascript 的图像滑块 carosual https://www.instagram.com/webstreet_code/
    ?带有缩略图和悬停效果的图像轮播? 嘿,开发社区! ? 在我的最新视频中,我构建了一个优雅的图像轮播,其缩略图突出显示具有平滑悬停效果的活动图像。这种交互式设计增强了用户参与度,并为您的 Web 项目增添了现代感。 主要特点: 响应式布局:轮播在所有屏幕尺寸上都能完美调整。 交互式缩略图:可点击的缩...
    编程 发布于2024-11-12
  • React 的核心:理解组件重新渲染
    React 的核心:理解组件重新渲染
    在学习编程语言时,我们经常深入研究语法并专注于快速构建某些东西,有时会忽略一个关键问题:这种语言实际上解决了什么问题,以及它在幕后如何工作?将我们的注意力转移到理解语言的核心目的和机制上,可以让学习速度更快、适应性更强,使我们能够轻松驾驭最复杂的项目。语法总是可以查找的——即使是最经验丰富的开发人员...
    编程 发布于2024-11-12
  • JavaScript 中的 Deferreds、Promise 和 Future 之间有什么区别?
    JavaScript 中的 Deferreds、Promise 和 Future 之间有什么区别?
    JavaScript 中 Deferreds、Promise 和 Future 的区别在 JavaScript 中,deferreds、promise 和 futures 通常用于处理异步操作。这些概念中的每一个都有其独特的一组特征:Deferreds在正式文档中从未明确定义,deferreds 通...
    编程 发布于2024-11-12
  • 为什么我的 Web 应用程序中的请求之间没有维护 Gorilla 会话变量?
    为什么我的 Web 应用程序中的请求之间没有维护 Gorilla 会话变量?
    使用 Gorilla 会话时未维护会话变量问题使用 Gorilla Sessions Web 工具包时,会话变量不会跨请求保留。当服务器启动并且用户访问 localhost:8100/ 时,他们将被定向到 login.html,因为会话值不存在。登录后,会话变量将被存储,并且用户将被重定向到 hom...
    编程 发布于2024-11-12
  • 如何在Python中像“column -t”命令一样显示列化数据?
    如何在Python中像“column -t”命令一样显示列化数据?
    在 Python 中显示列式数据在命令行管理工具领域,通常需要以良好对齐的方式呈现数据列。虽然制表符提供了一种简单的解决方案,但在处理不同长度的数据时它们会失败。本文旨在通过提出受 Linux“column -t”命令行为启发的 Python 解决方案来应对这一挑战。Python 提供了一个强大的解...
    编程 发布于2024-11-12
  • 在 NumPy 数组中查找特定行的有效方法:问题和解决方案
    在 NumPy 数组中查找特定行的有效方法:问题和解决方案
    高效查找 NumPy 数组中特定行的实例使用 NumPy 数组时,可能会遇到需要确定是否array 包含特定行,但 ndarray 的标准 contains 方法引发了问题。本文针对此问题提出了高效且 Python 的解决方案。一种方法涉及使用 .tolist() 将 NumPy 数组转换为 Pyt...
    编程 发布于2024-11-12
  • 如何解决在服务器上使用 Matplotlib 的 Python 脚本的“_tkinter.TclError:无显示名称且无 $DISPLAY 环境变量”问题?
    如何解决在服务器上使用 Matplotlib 的 Python 脚本的“_tkinter.TclError:无显示名称且无 $DISPLAY 环境变量”问题?
    _tkinter.TclError:没有显示名称,也没有 $DISPLAY 环境变量问题使用 Matplotlib 的 Python 脚本在服务器上失败,并出现错误“生成绘图时没有显示名称和 $DISPLAY 环境变量”。出现此问题的原因是 Matplotlib 默认使用 Xwindows 后端,并...
    编程 发布于2024-11-12
  • 如何使用 Apache Commons IO 在 Java 中递归删除目录?
    如何使用 Apache Commons IO 在 Java 中递归删除目录?
    在 Java 中递归删除目录在 Java 中删除空目录非常简单。然而,当处理包含子目录和文件的目录时,该过程变得更加复杂。本文深入探讨了使用 Apache Commons IO 库递归删除整个目录的有效方法。Apache Commons IO 简介Apache Commons IO 提供了一套全面的...
    编程 发布于2024-11-12

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3