Skip to main content

A cocoa core data timestamp library

Project description

Details

Author: Edan

Version: 1.0.10

A cocoa core data timestamp library


Documentation

Steps

1. Installation

pip install cocoa_time

2. Import

Import cocoa_time as cocoa for short as long as you as you don't have a conflicting package with the same name.

import cocoa_time as cocoa

Samples

Sample of a cocoa timestamp

747755750 is a cocoa timestamp that represents the date Wednesday, September 11, 2024 1:55:50 PM and is equal to 1726062950 in unix timestamp

Cocoa timestamp can come with 2 more decimals that represent centi seconds this timestamp: 747755750 will be 74775575000 with centi seconds a 9 digit and 11 digit cocoa timestamp


Functions

Introduction

There are 4 functions in total

  1. to_datetime
  2. to_unix_timestamp
  3. from_unix_timestamp
  4. from_datetime

to_datetime

returns a conversion of cocoa timestamp to datetime

Parameters

timestamp: int | str

cocoa.to_datetime(timestamp)

Example

prints a datetime object converted from a cocoa timestamp

import cocoa_time as cocoa

#cocoa_timestamp = "747755750" # timestamp can also be a string that contains only numbers
timestamp = 747755750
date = cocoa.to_datetime(timestamp)

print(date)

Result:
2024-09-11 13:55:50


to_unix_timestamp

returns a conversion of cocoa timestamp to unix timestamp

Parameters

timestamp: int | str

cocoa.to_unix_timestamp(cocoa_timestamp)

Example

prints an int with the value 1726062950 in this case (a conversion of the cocoa timestamp int to a unix timestamp int)

import cocoa_time as cocoa

#timestamp = "747755750" # cocoa_timestamp can also be a string that contains only numbers
cocoa_timestamp = 747755750
unix_timestamp = cocoa.to_unix_timestamp(cocoa_timestamp)

print(unix_timestamp)

Result:
1726062950


from_unix_timestamp

returns a conversion of a unix timestamp to cocoa timestamp

Parameters

timestamp: int | str
centi seconds: bool = False

cocoa_timestamp = cocoa.from_unix_timestamp(unix_timestamp)

Example #1

prints a 9 digit int with the value 747755750 in this case (a conversion of the unix timestamp int to a cocoa timestamp int)

import cocoa_time as cocoa

#unix_timestamp = "1726062950" # unix_timestamp can also be a string that contains only numbers
unix_timestamp = 1726062950
cocoa_timestamp = cocoa.from_unix_timestamp(unix_timestamp)

print(cocoa_timestamp)

Result:
747755750


Example #2

prints an 11 digit int with the value 74775575000 in this case (a conversion of the unix timestamp int to a cocoa timestamp int)

import cocoa_time as cocoa

#unix_timestamp = "1726062950" # unix_timestamp can also be a string that contains only numbers
unix_timestamp = 1726062950
cocoa_timestamp = cocoa.from_unix_timestamp(unix_timestamp, True)

# Longer version that has the centi seconds parameter name
cocoa_timestamp = cocoa.from_unix_timestamp(unix_timestamp, centiseconds = True)

print(cocoa_timestamp)

Result:
74775575000


from_datetime

Converts a datetime object or a string with a provided format string to cocoa timestamp

Parameters

date: datetime | str
centiseconds: bool = False
format: str | None = None

cocoa_timestamp = cocoa.from_datetime(date)
cocoa_timestamp = cocoa.from_datetime(date_string, format=date_format)

Note:

Format must be provided when date is of type string otherwise it must stay None when date is a datetime class


Example #1

prints a 9 digit int that is the cocoa timestamp of datetime.now() date value can be replaced with another value of type datetime object

from datetime import datetime
import cocoa_time as cocoa

date = datetime.now()
cocoa_timestamp = cocoa.from_datetime(date)

print(cocoa_timestamp)

results varies based on date provided so an example result won't be provided here


Example #2

prints a 11 digit int that is the cocoa timestamp of datetime.now() date value can be replaced with another value of type datetime object

from datetime import datetime
import cocoa_time as cocoa

# For a centi second 11 digit cocoa timestamp

date = datetime.now()
cocoa_timestamp = cocoa.from_datetime(date, True)

# Longer version that has the centi seconds parameter name
# cocoa_timestamp = cocoa.from_datetime(date, centiseconds = True)

print(cocoa_timestamp)

results varies based on date provided so an example result won't be provided here


Example #3

prints a 9 digit int that is the cocoa timestamp of the formatted date string a format string must be provided as well

import cocoa_time as cocoa

date_string = "01/01/2002 00:00:00"
cocoa_timestamp = cocoa.from_datetime(date_string, format="%d/%m/%Y %H:%M:%S")

print(cocoa_timestamp)

Result:
31536000


Example #4

prints an 11 digit int that is the cocoa timestamp of the formatted date string a format string must be provided as well

import cocoa_time as cocoa

date_string = "01/01/2002 00:00:00"
cocoa_timestamp = cocoa.from_datetime(date_string, format="%d/%m/%Y %H:%M:%S", centiseconds=True)

print(cocoa_timestamp)

Result:
3153600000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocoa_time-1.0.10.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

cocoa_time-1.0.10-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file cocoa_time-1.0.10.tar.gz.

File metadata

  • Download URL: cocoa_time-1.0.10.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for cocoa_time-1.0.10.tar.gz
Algorithm Hash digest
SHA256 98db6f3c24b5ea79a368c01546d3f5161ea7bf0cd6909c4e69d9b7e27ec7b3e9
MD5 03bdf15141ed245f0c7e50d07f41f744
BLAKE2b-256 b98bff16223286d6990fa5b3d7a50553aa9db6564bb4453d9bc2b2740aec7901

See more details on using hashes here.

File details

Details for the file cocoa_time-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: cocoa_time-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for cocoa_time-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 482004e4f6388a24be44abef3819be2cacc442257e4a3dd7226781571231f65a
MD5 916e73efdc393bdb152ed14176da75fe
BLAKE2b-256 9a8fc4474d5ae574ca82c5e2fe40990dd56571145c0a27466293af8ef7579902

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page