Python 3时钟管理模块每一个时钟都会带有它的参考时间和时区。参照期可以配置,可能不同于UNIX时代(1970-01-01T00:00:00)。

aaaahorodatage的Python项目详细描述


aaa水平

该程序是在GNU通用公共许可,第3版,见许可文本文件。

这个程序需要python 3和aaaa.ahordat、aaaa.ahordattools模块。

aaa水平格式

[0-9]+aaaa z++hh:mm,其中[0-9]+=从纪元到输入日期的秒数,aaaa=时间戳的纪元,z++hh:mm是UTC偏移量(例如,对于CEST SummerTime:z+02:00)。时区和纪元已嵌入。

下面,与这个readme.md文件位于同一目录中

用法

在文件中.py:

from aaaa.ahordat import AaaaHorodatageTools
<your code>

代莫

在python shel中,例如:

from aaaa.demo import demo
demo()

初始:

from aaaa.ahordattools import AaaaHorodatageTools

new_ts_object = AaaaHorodatageTools()
or
new_ts_object = AaaaHorodatageTools(AaaaTimestamp)
or
new_ts_object = AaaaHorodatageTools("server")

... your code ...

示例:

  • 新对象=aaaahorodatagetools()将创建2000z+02:00=2000-01-01t00:00+02:00,嵌入式epoch=2000(默认)。
  • new_ts_object=aaaahorodatagetools(“server”)将使用时间服务器utc创建ts_对象。

修饰语

aaaahordatage实例有一个公共实例属性:self.ts(其时间戳)。

我调用修饰符的一些方法可以更改此属性;它们将用update self.ts记录。

生成时间戳

encode(d="", utc=False) # possible inputs:
    update and return self.ts
    d="": keyboard input
    d= list, tuple or dictionary.
    utc=False: Local UTC offset encoding (see "Setting your timezone")
    utc=True: UTC encoding

decode("typ", ts="") 
    return typ = "string", "list", "dict" ou "dictionary"
    ts = timestamp (e.g.: ts_object.get_ts()): use ts.
    ts = none or "": use self.ts.

注:将年份编码为9999,epoch=1000可能会导致长时间计算。

时间戳复制

很肤浅的复制品,但这里就足够了。

new_ts_object = ts_object.copy()

协调历元和UTC偏移

将ts_object_转换为与ts_object一致的纪元和utc偏移量

ts_object.set_ts_same_epoch_offset(ts_object_to_harmonize)
    ts_object_to_harmonize.ts is updated

时区

设置时区

本地时区存储在utc_local_offset类属性中 默认值为+7200秒,即+02:00;欧洲/布鲁塞尔夏季时间 utc_本地偏移量范围:-43200>;=utc秒<;=+50400
时间戳EMBBE了它们自己的UTC偏移量,那么这个属性只是用于编码时间戳。

您可以使用公共方法获取或设置它。

get_utc_local_offset(typ="") # instance method
    typ="": default, seconds (integer); typ="string": "+/-HH:MM"
    Return _utc_local_offset

set_utc_local_offset(*offset) # class method
    work with encode(). Default +02:00
    -43200 >= *offset <= +50400 or '-12:00' >= *offset <= '+14:00'

获取嵌入的UTC偏移量(self.ts中嵌入的UTC偏移量)

get_utc_ts_offset(typ=""):
    typ="": default, seconds (integer); typ="string": "+/-HH:MM" 
    return the embedded UTC offset

转换时区

您可以使用方法将时间戳从UTC转换为特定时区,并从特定时区转换为UTC。

tz2utc()
    update and return self.ts

utc2tz(*new_offset) 
    update and return self.ts

    -43200 >= *new_offset <= +50400 or 
    '-12:00' >= *new_offset <= '+14:00'. 

转换偏移量

可以使用此实用程序方法将偏移量从秒转换为字符串,从字符串转换为秒。

offset_seconds2string(offset_seconds)  # -43200 >= *new_offset <= +50400
offset_string2seconds(offset_string)  # no control

时区站点

一些时区网站可以帮助您确定旅游时区。

历元

存储在epoch类属性
默认值为2000。范围:1000<;=epoch<;=9999。
epoch属性仅用于编码时间戳。对于解码,脚本使用嵌入的epoch。解码时接受小于epoch类属性的时间戳epoch。

设定历元

您可以使用这个类方法来获取或设置它。

get_epoch() 
set_epoch(num)  #  1000 <= epoch <= 9999, return epoch

转换历元

您可以更改和调整时间戳的嵌入纪元。

convert2epoch(epoch) 
    update and return self.ts
    Convert an embedded epoch to an other. 
    1000 <= epoch <= 9999.

操作

操作只与同一个UTC偏移量和同一个历元的时间戳相关。

差异

也可参见~-operator™

ts1_object.diffDays(typ="string", ts2=0) 
    return ts2 - self.ts1 in days, hours, minutes, seconds.
    Offset UTC timestamp 1 must match offset UTC timestamp 2 and epoch timestamp 1 must match epoch timestamp 2.
    Return typ =
        - "seconds": return the number of seconds.
        - "string": return a string (+/-DDTHH:MM:SS). Default.
        - "list": return a list (fixed order).
        fixed order: sens_difference, day, hour, minutes, seconds.
        - "dict" or "dictionary": return a dict (any order).
    ts2 = 0 or none: keyboard input.
    ts2 eg: ts2_object.get_ts()

使用ts1_object.diffdays的提示(typ=“string”,ts2=0)
我想要ts1_对象、epoch 2000和offset+02:00之间的diffdays,以及ts2_对象、epoch 1900和offset+08:00之间的diffdays,但不更新ts2_对象。
考虑以下提示:

ts3_object = ts2_object.copy()
ts1_object.set_ts_same_epoch_offset(ts_object3)
diff_ts2_ts1 = ts1_object.diffDays("string", ts3_object.get_ts())
del ts3_object

+操作员

+ operator: ts_object = ts_object + nb_seconds
    update self.ts and return ts_object + nb_seconds
    Add nb_seconds at timestamp
    Tips: 
    - use dhms2second(d=0, h=0, m=0, s=0) utility method 
    to convert days + hours + minutes + seconds in seconds
    - To add seconds to a new timestamp instance:
    new_ts_object = ts_object.copy()
    new_ts_object - nb_seconds

-操作员

- operator: new_ts = ts_object - *nb_seconds_or_ts_object
    if *nb_seconds_or_ts_object is a nb_seconds integer
    update self.ts and return ts_object - *nb_seconds
    self.ts seconds - seconds must be >= 0 (epoch-01-01)

    if *nb_seconds_or_ts_object is ts_object, call
    self.ts.diffDays("string", *nb_seconds_or_ts_object.get_ts())
    self.ts is NOT updated. See diffDays() method above.

    Tips: 
    - use dhms2second(d=0, h=0, m=0, s=0) utility method 
    to convert days + hours + minutes + seconds in seconds
    - To add seconds to a new timestamp instance:
    new_ts_object = ts_object.copy()
    new_ts_object - seconds

比较运算符

ts_object1 == ts_object2
ts_object1 != ts_object2
ts_object1 < ts_object2
ts_object1 <= ts_object2
ts_object1 > ts_object2
ts_object1 >= ts_object2

与posix的转换

ts_object.convert_aaaa2posix(aaaa_ts)
    Return a Posix timestamp (UTC) from an Aaaa timestamp

ts_object.convert_posix2aaaa(posix_ts):
    Return an Aaaa timestamp from a Posix timestamp
    update self.ts
    posix_ts will be considered at UTC time.

帮助:

import aaaa.ahordattools
help(aaaa.ahordattools)

简短演示

python3 main.py

您可以在这里找到有关算法的一些想法pdf document

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java应用程序不是在Eclipse中运行,而是在命令行中运行   swing Java图形组件问题。似乎找不到错误   我需要键盘。close();让代码正常工作?   Springboot中的java HttpSession   抽象语法树我想添加一个语句。我试图解析它,java解析器异常被抛出。如何克服它?   java Hibernate:清理会话   具有不连续子集的java划分问题   java正则表达式查找最后一个冒号后的字符串   java从SpringShell执行OS命令   Java扫描器字符串输入   java字符串索引越界异常(charAt)   java执行器服务终止被卡住   Springockito没有继承java@ContextConfiguration   java如何为一个servlet映射多个url   java安卓获取命令的stderr   java生成类型。表:数据库中的大数字   安卓 Getter Setter返回NothingJava